From c4d15c32c3f7baffdb28dddb285cab6d1e7c536c Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 30 Jun 2025 15:50:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=AD=94=E6=94=B9projectile=E4=BC=A4=E5=AE=B3?= =?UTF-8?q?=E5=88=A4=E5=AE=9A=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/ProjectileEntity.java | 140 +++--------------- .../superbwarfare/perk/AmmoPerk.java | 7 +- .../perk/ammo/IncendiaryBullet.java | 9 +- .../superbwarfare/perk/ammo/JHPBullet.java | 15 +- .../superbwarfare/perk/ammo/RiotBullet.java | 17 ++- .../superbwarfare/perk/ammo/SilverBullet.java | 4 +- .../perk/damage/MonsterHunter.java | 4 +- 7 files changed, 63 insertions(+), 133 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java index ad408a351..48fa6f5f4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -21,8 +21,6 @@ import net.minecraft.core.Direction; import net.minecraft.core.Holder; import net.minecraft.core.particles.BlockParticleOption; import net.minecraft.core.particles.ParticleTypes; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.game.ClientboundSoundPacket; import net.minecraft.network.syncher.EntityDataAccessor; @@ -39,11 +37,8 @@ import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.monster.Monster; -import net.minecraft.world.entity.monster.Ravager; import net.minecraft.world.entity.monster.Vex; -import net.minecraft.world.entity.monster.Witch; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.item.ItemStack; @@ -55,7 +50,6 @@ import net.minecraft.world.level.material.FluidState; import net.minecraft.world.phys.*; import net.minecraft.world.phys.shapes.VoxelShape; import net.neoforged.neoforge.common.Tags; -import net.neoforged.neoforge.entity.IEntityWithComplexSpawn; import net.neoforged.neoforge.entity.PartEntity; import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.network.PacketDistributor; @@ -74,7 +68,7 @@ import java.util.function.Predicate; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @SuppressWarnings({"unused", "UnusedReturnValue", "SuspiciousNameCombination"}) -public class ProjectileEntity extends Projectile implements IEntityWithComplexSpawn, GeoEntity, CustomSyncMotionEntity { +public class ProjectileEntity extends Projectile implements GeoEntity, CustomSyncMotionEntity { public static final EntityDataAccessor COLOR_R = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor COLOR_G = SynchedEntityData.defineId(ProjectileEntity.class, EntityDataSerializers.FLOAT); @@ -98,15 +92,10 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp protected int shooterId; private float damage = 1f; private float headShot = 1f; - private float monsterMultiplier = 0.0f; private float legShot = 0.5f; private boolean beast = false; private boolean zoom = false; private float bypassArmorRate = 0.0f; - private float undeadMultiple = 1.0f; - private float illagerMultiple = 1.0f; - private int riotLevel = 0; - private int jhpLevel = 0; private int heLevel = 0; private int fireLevel = 0; private boolean dragonBreath = false; @@ -115,6 +104,12 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp private final ArrayList mobEffects = new ArrayList<>(); private String gunItemId; + public static final Predicate MONSTER_PREDICATE = entity -> entity instanceof Monster; + public static final Predicate UNDEAD_PREDICATE = entity -> entity.getType().is(EntityTypeTags.UNDEAD); + public static final Predicate RAIDERS_PREDICATE = entity -> entity.getType().is(EntityTypeTags.RAIDERS) || entity instanceof Vex; + + private final Map, Float> damageModifiers = new HashMap<>(Map.of(MONSTER_PREDICATE, 1.0f)); + public ProjectileEntity(EntityType entityType, Level level) { super(entityType, level); this.noCulling = true; @@ -260,7 +255,7 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp } if (heLevel > 0) { - explosionBullet(this, this.damage, heLevel, monsterMultiplier + 1, hitPos); + explosionBullet(this, this.damage, heLevel, this.damageModifiers.get(MONSTER_PREDICATE), hitPos); } return new EntityResult(entity, hitPos, headshot, legShot); @@ -350,44 +345,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp } } - @Override - protected void readAdditionalSaveData(CompoundTag tag) { - this.damage = tag.getFloat("Damage"); - this.headShot = tag.getFloat("HeadShot"); - this.monsterMultiplier = tag.getFloat("MonsterMultiplier"); - this.legShot = tag.getFloat("LegShot"); - this.bypassArmorRate = tag.getFloat("BypassArmorRate"); - this.undeadMultiple = tag.getFloat("UndeadMultiple"); - this.illagerMultiple = tag.getFloat("IllagerMultiple"); - this.knockback = tag.getFloat("Knockback"); - - this.beast = tag.getBoolean("Beast"); - this.forceKnockback = tag.getBoolean("ForceKnockback"); - - if (tag.contains("GunId")) { - this.gunItemId = tag.getString("GunId"); - } - } - - @Override - protected void addAdditionalSaveData(CompoundTag tag) { - tag.putFloat("Damage", this.damage); - tag.putFloat("HeadShot", this.headShot); - tag.putFloat("MonsterMultiplier", this.monsterMultiplier); - tag.putFloat("LegShot", this.legShot); - tag.putFloat("BypassArmorRate", this.bypassArmorRate); - tag.putFloat("UndeadMultiple", this.undeadMultiple); - tag.putFloat("IllagerMultiple", this.illagerMultiple); - tag.putFloat("Knockback", this.knockback); - - tag.putBoolean("Beast", this.beast); - tag.putBoolean("ForceKnockback", this.forceKnockback); - - if (this.gunItemId != null) { - tag.putString("GunId", this.gunItemId); - } - } - @Override protected void onHit(@Nullable HitResult result) { if (result instanceof BlockHitResult blockHitResult) { @@ -420,7 +377,7 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp this.onHitBlock(hitVec, blockHitResult); if (heLevel > 0) { - explosionBullet(this, this.damage, heLevel, monsterMultiplier + 1, hitVec); + explosionBullet(this, this.damage, heLevel, this.damageModifiers.get(MONSTER_PREDICATE), hitVec); } if (fireLevel > 0 && this.level() instanceof ServerLevel serverLevel) { ParticleTool.sendParticle(serverLevel, ParticleTypes.LAVA, hitVec.x, hitVec.y, hitVec.z, @@ -533,8 +490,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp protected void onHitEntity(Entity entity, boolean headshot, boolean legShot) { if (this.shooter == null) return; - float mMultiple = 1 + this.monsterMultiplier; - if (entity == null) return; if (entity instanceof PartEntity part) { @@ -542,38 +497,17 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp } 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)); + living.level().playSound(null, living.getOnPos(), ModSounds.MELEE_HIT.get(), SoundSource.PLAYERS, 1, (float) (2 * Math.random() - 1) * 0.1f + 1.0f); + + if (beast) { + Beast.beastKill(this.shooter, living); + return; + } } - if (beast && entity instanceof LivingEntity living) { - Beast.beastKill(this.shooter, living); - return; - } - - if (entity instanceof Monster) { - this.damage *= mMultiple; - } - - if (entity instanceof LivingEntity living && living.getType().is(EntityTypeTags.UNDEAD)) { - this.damage *= this.undeadMultiple; - } - - if (entity instanceof LivingEntity living && (living.getType().is(EntityTypeTags.ILLAGER) || living instanceof Vex || living instanceof Ravager || living instanceof Witch)) { - this.damage *= this.illagerMultiple; - } - - if (entity instanceof LivingEntity living && riotLevel > 0 && !entity.level().isClientSide()) { - living.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 20 + riotLevel * 10, (int) (riotLevel * 0.25), false, false), this.shooter); - living.addEffect(new MobEffectInstance(MobEffects.WEAKNESS, 20 + riotLevel * 10, (int) (riotLevel * 0.25), false, false), this.shooter); - } - - if (entity instanceof LivingEntity living && jhpLevel > 0) { - this.damage *= (1.0f + 0.12f * jhpLevel) * ((float) (10 / (living.getAttributeValue(Attributes.ARMOR) + 10)) + 0.25f); - } - - if (fireLevel > 0) { - if (!entity.level().isClientSide() && entity instanceof LivingEntity living) { - living.addEffect(new MobEffectInstance(ModMobEffects.BURN, 60 + fireLevel * 20, fireLevel, false, false), this.shooter); + for (var entry : this.damageModifiers.entrySet()) { + if (entry.getKey().test(entity)) { + this.damage *= entry.getValue(); } } @@ -787,15 +721,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp } } - - @Override - public void readSpawnData(@NotNull RegistryFriendlyByteBuf additionalData) { - } - - @Override - public void writeSpawnData(@NotNull RegistryFriendlyByteBuf buffer) { - } - public static class EntityResult { private final Entity entity; private final Vec3 hitVec; @@ -853,6 +778,10 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp return this.gunItemId; } + public Map, Float> getDamageModifiers() { + return damageModifiers; + } + /** * Builders */ @@ -871,11 +800,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp return this; } - public ProjectileEntity setMonsterMultiplier(float monsterMultiplier) { - this.monsterMultiplier = monsterMultiplier; - return this; - } - public ProjectileEntity legShot(float legShot) { this.legShot = legShot; return this; @@ -886,16 +810,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp return this; } - public ProjectileEntity riotBullet(int riotLevel) { - this.riotLevel = riotLevel; - return this; - } - - public ProjectileEntity jhpBullet(int jhpLevel) { - this.jhpLevel = jhpLevel; - return this; - } - public ProjectileEntity heBullet(int heLevel) { this.heLevel = heLevel; return this; @@ -917,16 +831,6 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp return this; } - public ProjectileEntity undeadMultiple(float undeadMultiple) { - this.undeadMultiple = undeadMultiple; - return this; - } - - public ProjectileEntity illagerMultiple(float illagerMultiple) { - this.illagerMultiple = illagerMultiple; - return this; - } - public ProjectileEntity effect(ArrayList mobEffectInstances) { this.mobEffects.addAll(mobEffectInstances); return this; diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java index 5897fc009..3c62df6fd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java @@ -47,9 +47,10 @@ public class AmmoPerk extends Perk { } if (!this.mobEffects.get().isEmpty()) { int amplifier = this.getEffectAmplifier(instance); + int duration = this.getEffectDuration(instance); ArrayList mobEffectInstances = new ArrayList<>(); for (MobEffect effect : this.mobEffects.get()) { - mobEffectInstances.add(new MobEffectInstance(Holder.direct(effect), 70 + 30 * level, amplifier)); + mobEffectInstances.add(new MobEffectInstance(Holder.direct(effect), duration, amplifier)); } projectile.effect(mobEffectInstances); } @@ -59,6 +60,10 @@ public class AmmoPerk extends Perk { return instance.level() - 1; } + public int getEffectDuration(PerkInstance instance) { + return 70 + 30 * instance.level(); + } + public double getModifiedVelocity(GunData data, PerkInstance instance) { return data.velocity() * this.speedRate; } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/IncendiaryBullet.java b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/IncendiaryBullet.java index 460091d98..4f84f2407 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/IncendiaryBullet.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/IncendiaryBullet.java @@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.perk.ammo; import com.atsuishio.superbwarfare.data.gun.GunData; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; +import com.atsuishio.superbwarfare.init.ModMobEffects; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; @@ -11,7 +12,13 @@ import net.minecraft.world.entity.Entity; public class IncendiaryBullet extends AmmoPerk { public IncendiaryBullet() { - super(new AmmoPerk.Builder("incendiary_bullet", Perk.Type.AMMO).bypassArmorRate(-0.4f).damageRate(0.7f).speedRate(0.75f).slug(false).rgb(230, 131, 65)); + super(new AmmoPerk.Builder("incendiary_bullet", Perk.Type.AMMO).bypassArmorRate(-0.4f).damageRate(0.7f).speedRate(0.75f).slug(false).rgb(230, 131, 65) + .mobEffect(ModMobEffects.BURN)); + } + + @Override + public int getEffectDuration(PerkInstance instance) { + return 60 + 20 * instance.level(); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/JHPBullet.java b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/JHPBullet.java index 1b06d889d..489963a9f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/JHPBullet.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/JHPBullet.java @@ -1,11 +1,13 @@ package com.atsuishio.superbwarfare.perk.ammo; import com.atsuishio.superbwarfare.data.gun.GunData; -import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkInstance; -import net.minecraft.world.entity.Entity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.attributes.Attributes; +import org.jetbrains.annotations.Nullable; public class JHPBullet extends AmmoPerk { @@ -14,9 +16,10 @@ public class JHPBullet extends AmmoPerk { } @Override - public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { - super.modifyProjectile(data, instance, entity); - if (!(entity instanceof ProjectileEntity projectile)) return; - projectile.jhpBullet(instance.level()); + public float getModifiedDamage(float damage, GunData data, PerkInstance instance, @Nullable LivingEntity target, DamageSource source) { + if (target != null) { + return damage * (1.0f + 0.12f * instance.level()) * ((float) (10 / (target.getAttributeValue(Attributes.ARMOR) + 10)) + 0.25f); + } + return super.getModifiedDamage(damage, data, instance, null, source); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/RiotBullet.java b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/RiotBullet.java index c5e4f005b..f452d516e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/RiotBullet.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/RiotBullet.java @@ -4,19 +4,30 @@ import com.atsuishio.superbwarfare.data.gun.GunData; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.PerkInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; public class RiotBullet extends AmmoPerk { public RiotBullet() { - super(new Builder("riot_bullet", Type.AMMO).bypassArmorRate(-0.3f).damageRate(0.9f).speedRate(0.8f).slug(true).rgb(70, 35, 230)); + super(new Builder("riot_bullet", Type.AMMO).bypassArmorRate(-0.3f).damageRate(0.9f).speedRate(0.8f).slug(true).rgb(70, 35, 230) + .mobEffect(MobEffects.MOVEMENT_SLOWDOWN::value).mobEffect(MobEffects.WEAKNESS::value)); + } + + @Override + public int getEffectAmplifier(PerkInstance instance) { + return (int) (instance.level() * 0.25); + } + + @Override + public int getEffectDuration(PerkInstance instance) { + return 20 + instance.level() * 10; } @Override public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { super.modifyProjectile(data, instance, entity); if (!(entity instanceof ProjectileEntity projectile)) return; - projectile.riotBullet(instance.level()); - projectile.illagerMultiple(1.0f + 0.5f * instance.level()); + projectile.getDamageModifiers().put(ProjectileEntity.RAIDERS_PREDICATE, 1.0f + 0.5f * instance.level()); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/SilverBullet.java b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/SilverBullet.java index a87ea2563..dae81a63b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/SilverBullet.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/SilverBullet.java @@ -1,7 +1,7 @@ package com.atsuishio.superbwarfare.perk.ammo; -import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.data.gun.GunData; +import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkInstance; @@ -17,6 +17,6 @@ public class SilverBullet extends AmmoPerk { public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { super.modifyProjectile(data, instance, entity); if (!(entity instanceof ProjectileEntity projectile)) return; - projectile.undeadMultiple(1.0f + 0.5f * instance.level()); + projectile.getDamageModifiers().put(ProjectileEntity.UNDEAD_PREDICATE, 1.0f + 0.5f * instance.level()); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/damage/MonsterHunter.java b/src/main/java/com/atsuishio/superbwarfare/perk/damage/MonsterHunter.java index 31f63833d..ae22e1975 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/damage/MonsterHunter.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/damage/MonsterHunter.java @@ -17,9 +17,9 @@ public class MonsterHunter extends Perk { @Override public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { - float multiplier = 0.1f + 0.1f * instance.level(); + float multiplier = 1.1f + 0.1f * instance.level(); if (entity instanceof ProjectileEntity projectile) { - projectile.setMonsterMultiplier(multiplier); + projectile.getDamageModifiers().put(ProjectileEntity.MONSTER_PREDICATE, multiplier); } else if (entity instanceof JavelinMissileEntity projectile) { projectile.setMonsterMultiplier(multiplier); } else if (entity instanceof GunGrenadeEntity projectile) {