From 72da5c171e12383554625347dddab9da4010aa2f Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Thu, 28 Nov 2024 02:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9projectile=E7=9A=84effect?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/projectile/ProjectileEntity.java | 19 ++++++++++--------- .../superbwarfare/event/GunEventHandler.java | 10 ++++++++-- .../network/message/FireMessage.java | 10 ++++++++-- .../superbwarfare/perk/AmmoPerk.java | 11 +++++++---- 4 files changed, 33 insertions(+), 17 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 29336954c..d58c0a56f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/ProjectileEntity.java @@ -1,16 +1,16 @@ package com.atsuishio.superbwarfare.entity.projectile; -import com.atsuishio.superbwarfare.entity.*; -import com.atsuishio.superbwarfare.init.*; -import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.block.BarbedWireBlock; +import com.atsuishio.superbwarfare.entity.*; +import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.Transcript; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.PlayerGunKillMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ExtendedEntityRayTraceResult; import com.atsuishio.superbwarfare.tools.HitboxHelper; +import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Holder; @@ -64,7 +64,6 @@ import java.util.*; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; -import java.util.function.Supplier; @SuppressWarnings({"unused", "UnusedReturnValue", "SuspiciousNameCombination"}) public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnData, GeoEntity, AnimatedEntity { @@ -101,7 +100,7 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa private boolean fireBullet = false; private int fireLevel = 0; private boolean dragonBreath = false; - private Supplier mobEffect = () -> null; + private final ArrayList mobEffects = new ArrayList<>(); public ProjectileEntity(EntityType p_i50159_1_, Level p_i50159_2_) { super(p_i50159_1_, p_i50159_2_); @@ -554,8 +553,10 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa performDamage(entity, this.damage, false); } - if (this.mobEffect.get() != null && entity instanceof LivingEntity living) { - living.addEffect(this.mobEffect.get(), this.shooter); + if (!this.mobEffects.isEmpty() && entity instanceof LivingEntity living) { + for (MobEffectInstance instance : this.mobEffects) { + living.addEffect(instance, this.shooter); + } } this.discard(); @@ -847,8 +848,8 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa return this; } - public ProjectileEntity effect(Supplier supplier) { - this.mobEffect = supplier; + public ProjectileEntity effect(ArrayList mobEffectInstances) { + this.mobEffects.addAll(mobEffectInstances); return this; } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 31d6a61b3..d70e27c69 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -20,6 +20,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.Projectile; @@ -33,6 +34,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ForgeRegistries; +import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; @Mod.EventBusSubscriber @@ -205,7 +207,7 @@ public class GunEventHandler { bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0); projectile.setRGB(ammoPerk.rgb); - if (ammoPerk.mobEffect.get() != null) { + if (!ammoPerk.mobEffects.get().isEmpty()) { int amplifier; if (perk.descriptionId.equals("blade_bullet")) { amplifier = level / 3; @@ -213,7 +215,11 @@ public class GunEventHandler { amplifier = level - 1; } - projectile.effect(() -> new MobEffectInstance(ammoPerk.mobEffect.get(), 70 + 30 * level, amplifier)); + ArrayList mobEffectInstances = new ArrayList<>(); + for (MobEffect effect : ammoPerk.mobEffects.get()) { + mobEffectInstances.add(new MobEffectInstance(effect, 70 + 30 * level, amplifier)); + } + projectile.effect(mobEffectInstances); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/FireMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/FireMessage.java index 57f56364a..6ce69a279 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/FireMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/FireMessage.java @@ -24,6 +24,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; +import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; @@ -35,6 +36,7 @@ import net.minecraftforge.network.NetworkEvent; import net.minecraftforge.network.PacketDistributor; import org.joml.Vector3d; +import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -266,8 +268,12 @@ public class FireMessage { bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0); projectile.setRGB(ammoPerk.rgb); - if (ammoPerk.mobEffect.get() != null) { - projectile.effect(() -> new MobEffectInstance(ammoPerk.mobEffect.get(), 70 + 30 * level, level - 1)); + if (!ammoPerk.mobEffects.get().isEmpty()) { + ArrayList mobEffectInstances = new ArrayList<>(); + for (MobEffect effect : ammoPerk.mobEffects.get()) { + mobEffectInstances.add(new MobEffectInstance(effect, 70 + 30 * level, level - 1)); + } + projectile.effect(mobEffectInstances); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java index 513d0eb81..4be6edfc8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java +++ b/src/main/java/com/atsuishio/superbwarfare/perk/AmmoPerk.java @@ -3,15 +3,17 @@ package com.atsuishio.superbwarfare.perk; import net.minecraft.util.Mth; import net.minecraft.world.effect.MobEffect; +import java.util.ArrayList; import java.util.function.Supplier; public class AmmoPerk extends Perk { + public float bypassArmorRate; public float damageRate; public float speedRate; public boolean slug; public float[] rgb; - public Supplier mobEffect; + public Supplier> mobEffects; public AmmoPerk(AmmoPerk.Builder builder) { super(builder.descriptionId, builder.type); @@ -20,10 +22,11 @@ public class AmmoPerk extends Perk { this.speedRate = builder.speedRate; this.slug = builder.slug; this.rgb = builder.rgb; - this.mobEffect = builder.mobEffect; + this.mobEffects = () -> builder.mobEffects; } public static class Builder { + String descriptionId; Type type; float bypassArmorRate = 0.0f; @@ -31,7 +34,7 @@ public class AmmoPerk extends Perk { float speedRate = 1.0f; boolean slug = false; float[] rgb = {1, 222 / 255f, 39 / 255f}; - public Supplier mobEffect = () -> null; + public ArrayList mobEffects = new ArrayList<>(); public Builder(String descriptionId, Type type) { this.descriptionId = descriptionId; @@ -66,7 +69,7 @@ public class AmmoPerk extends Perk { } public AmmoPerk.Builder mobEffect(Supplier mobEffect) { - this.mobEffect = mobEffect; + this.mobEffects.add(mobEffect.get()); return this; } }