From 7a24ea05d19d297c9d7e664d0166eb480c3dd24f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Wed, 7 May 2025 14:54:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=A4=E4=B8=AAtaser?= =?UTF-8?q?=E7=9A=84perk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/TaserBulletEntity.java | 30 +++++++++++++++++++ .../superbwarfare/init/ModPerks.java | 4 +-- .../item/gun/special/TaserItem.java | 20 ++++++++----- .../superbwarfare/perk/AmmoPerk.java | 6 ++++ .../superbwarfare/perk/ammo/LongerWire.java | 22 ++++++++++++++ .../perk/damage/VoltOverload.java | 21 +++++++++++++ 6 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/perk/ammo/LongerWire.java create mode 100644 src/main/java/com/atsuishio/superbwarfare/perk/damage/VoltOverload.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/TaserBulletEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/TaserBulletEntity.java index a981e14b5..7972f1e23 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/TaserBulletEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/TaserBulletEntity.java @@ -52,10 +52,40 @@ public class TaserBulletEntity extends AbstractArrow implements GeoEntity { this.wireLength = wireLength; } + public TaserBulletEntity(LivingEntity entity, Level level, float damage) { + super(ModEntities.TASER_BULLET.get(), level); + this.damage = damage; + } + public TaserBulletEntity(EntityType type, Level world) { super(type, world); this.noCulling = true; } + + public float getDamage() { + return damage; + } + + public void setDamage(float damage) { + this.damage = damage; + } + + public int getVolt() { + return volt; + } + + public void setVolt(int volt) { + this.volt = volt; + } + + public int getWireLength() { + return wireLength; + } + + public void setWireLength(int wireLength) { + this.wireLength = wireLength; + } + @Override public void playerTouch(@NotNull Player pEntity) { } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModPerks.java b/src/main/java/com/atsuishio/superbwarfare/init/ModPerks.java index 34ed98fb6..1e1c4f7c4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModPerks.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModPerks.java @@ -38,7 +38,7 @@ public class ModPerks { () -> new AmmoPerk(new AmmoPerk.Builder("poisonous_bullet", Perk.Type.AMMO).bypassArmorRate(0.0f).damageRate(1.0f).speedRate(1.0f).rgb(48, 131, 6) .mobEffect(MobEffects.POISON::value))); public static final DeferredHolder BEAST_BULLET = AMMO_PERKS.register("beast_bullet", BeastBullet::new); - public static final DeferredHolder LONGER_WIRE = AMMO_PERKS.register("longer_wire", () -> new Perk("longer_wire", Perk.Type.AMMO)); + public static final DeferredHolder LONGER_WIRE = AMMO_PERKS.register("longer_wire", LongerWire::new); public static final DeferredHolder INCENDIARY_BULLET = AMMO_PERKS.register("incendiary_bullet", IncendiaryBullet::new); public static final DeferredHolder MICRO_MISSILE = AMMO_PERKS.register("micro_missile", MicroMissile::new); @@ -66,7 +66,7 @@ public class ModPerks { public static final DeferredHolder KILLING_TALLY = DAMAGE_PERKS.register("killing_tally", KillingTally::new); public static final DeferredHolder HEAD_SEEKER = DAMAGE_PERKS.register("head_seeker", HeadSeeker::new); public static final DeferredHolder MONSTER_HUNTER = DAMAGE_PERKS.register("monster_hunter", MonsterHunter::new); - public static final DeferredHolder VOLT_OVERLOAD = DAMAGE_PERKS.register("volt_overload", () -> new Perk("volt_overload", Perk.Type.DAMAGE)); + public static final DeferredHolder VOLT_OVERLOAD = DAMAGE_PERKS.register("volt_overload", VoltOverload::new); public static final DeferredHolder DESPERADO = DAMAGE_PERKS.register("desperado", Desperado::new); public static final DeferredHolder VORPAL_WEAPON = DAMAGE_PERKS.register("vorpal_weapon", VorpalWeapon::new); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java index f0e34ad36..ca1cc4294 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java @@ -181,17 +181,21 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem { player.getCooldowns().addCooldown(stack.getItem(), 5); if (player instanceof ServerPlayer serverPlayer) { - int volt = data.perk.getLevel(ModPerks.VOLT_OVERLOAD); - int wireLength = data.perk.getLevel(ModPerks.LONGER_WIRE); - var level = serverPlayer.level(); - TaserBulletEntity taserBulletProjectile = new TaserBulletEntity(player, level, - (float) data.damage(), volt, wireLength); + TaserBulletEntity projectile = new TaserBulletEntity(player, level, + (float) data.damage()); - taserBulletProjectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); - taserBulletProjectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) data.velocity(), + for (Perk.Type type : Perk.Type.values()) { + var instance = data.perk.getInstance(type); + if (instance != null) { + instance.perk().modifyProjectile(data, instance, projectile); + } + } + + projectile.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ()); + projectile.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, (float) data.velocity(), (float) (zoom ? 0.1 : spread)); - level.addFreshEntity(taserBulletProjectile); + level.addFreshEntity(projectile); } return true; } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java index 48d48d65e..cd98b260f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java @@ -30,6 +30,12 @@ public class AmmoPerk extends Perk { this.mobEffects = () -> builder.mobEffects; } + public AmmoPerk(String descriptionId, Type type) { + super(descriptionId, type); + this.rgb = new float[]{1, 222 / 255f, 39 / 255f}; + this.mobEffects = ArrayList::new; + } + @Override public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { if (!(entity instanceof ProjectileEntity projectile)) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/ammo/LongerWire.java b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/LongerWire.java new file mode 100644 index 000000000..d4a124314 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/perk/ammo/LongerWire.java @@ -0,0 +1,22 @@ +package com.atsuishio.superbwarfare.perk.ammo; + +import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity; +import com.atsuishio.superbwarfare.item.gun.data.GunData; +import com.atsuishio.superbwarfare.perk.AmmoPerk; +import com.atsuishio.superbwarfare.perk.Perk; +import com.atsuishio.superbwarfare.perk.PerkInstance; +import net.minecraft.world.entity.Entity; + +public class LongerWire extends AmmoPerk { + + public LongerWire() { + super("longer_wire", Perk.Type.AMMO); + } + + @Override + public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { + if (entity instanceof TaserBulletEntity taserBulletEntity) { + taserBulletEntity.setWireLength(instance.level()); + } + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/damage/VoltOverload.java b/src/main/java/com/atsuishio/superbwarfare/perk/damage/VoltOverload.java new file mode 100644 index 000000000..3c832f4cc --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/perk/damage/VoltOverload.java @@ -0,0 +1,21 @@ +package com.atsuishio.superbwarfare.perk.damage; + +import com.atsuishio.superbwarfare.entity.projectile.TaserBulletEntity; +import com.atsuishio.superbwarfare.item.gun.data.GunData; +import com.atsuishio.superbwarfare.perk.Perk; +import com.atsuishio.superbwarfare.perk.PerkInstance; +import net.minecraft.world.entity.Entity; + +public class VoltOverload extends Perk { + + public VoltOverload() { + super("volt_overload", Perk.Type.DAMAGE); + } + + @Override + public void modifyProjectile(GunData data, PerkInstance instance, Entity entity) { + if (entity instanceof TaserBulletEntity taserBulletEntity) { + taserBulletEntity.setVolt(instance.level()); + } + } +}