修改projectile的effect逻辑

This commit is contained in:
17146 2024-11-28 02:53:00 +08:00
parent 86ab10b40d
commit 72da5c171e
4 changed files with 33 additions and 17 deletions

View file

@ -1,16 +1,16 @@
package com.atsuishio.superbwarfare.entity.projectile; 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.ModUtils;
import com.atsuishio.superbwarfare.block.BarbedWireBlock; 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.item.Transcript;
import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.network.message.PlayerGunKillMessage; import com.atsuishio.superbwarfare.network.message.PlayerGunKillMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ExtendedEntityRayTraceResult; import com.atsuishio.superbwarfare.tools.ExtendedEntityRayTraceResult;
import com.atsuishio.superbwarfare.tools.HitboxHelper; import com.atsuishio.superbwarfare.tools.HitboxHelper;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
@ -64,7 +64,6 @@ import java.util.*;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.function.Supplier;
@SuppressWarnings({"unused", "UnusedReturnValue", "SuspiciousNameCombination"}) @SuppressWarnings({"unused", "UnusedReturnValue", "SuspiciousNameCombination"})
public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnData, GeoEntity, AnimatedEntity { 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 boolean fireBullet = false;
private int fireLevel = 0; private int fireLevel = 0;
private boolean dragonBreath = false; private boolean dragonBreath = false;
private Supplier<MobEffectInstance> mobEffect = () -> null; private final ArrayList<MobEffectInstance> mobEffects = new ArrayList<>();
public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) { public ProjectileEntity(EntityType<? extends ProjectileEntity> p_i50159_1_, Level p_i50159_2_) {
super(p_i50159_1_, 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); performDamage(entity, this.damage, false);
} }
if (this.mobEffect.get() != null && entity instanceof LivingEntity living) { if (!this.mobEffects.isEmpty() && entity instanceof LivingEntity living) {
living.addEffect(this.mobEffect.get(), this.shooter); for (MobEffectInstance instance : this.mobEffects) {
living.addEffect(instance, this.shooter);
}
} }
this.discard(); this.discard();
@ -847,8 +848,8 @@ public class ProjectileEntity extends Entity implements IEntityAdditionalSpawnDa
return this; return this;
} }
public ProjectileEntity effect(Supplier<MobEffectInstance> supplier) { public ProjectileEntity effect(ArrayList<MobEffectInstance> mobEffectInstances) {
this.mobEffect = supplier; this.mobEffects.addAll(mobEffectInstances);
return this; return this;
} }

View file

@ -20,6 +20,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile; 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.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
@ -205,7 +207,7 @@ public class GunEventHandler {
bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0); bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
projectile.setRGB(ammoPerk.rgb); projectile.setRGB(ammoPerk.rgb);
if (ammoPerk.mobEffect.get() != null) { if (!ammoPerk.mobEffects.get().isEmpty()) {
int amplifier; int amplifier;
if (perk.descriptionId.equals("blade_bullet")) { if (perk.descriptionId.equals("blade_bullet")) {
amplifier = level / 3; amplifier = level / 3;
@ -213,7 +215,11 @@ public class GunEventHandler {
amplifier = level - 1; amplifier = level - 1;
} }
projectile.effect(() -> new MobEffectInstance(ammoPerk.mobEffect.get(), 70 + 30 * level, amplifier)); ArrayList<MobEffectInstance> mobEffectInstances = new ArrayList<>();
for (MobEffect effect : ammoPerk.mobEffects.get()) {
mobEffectInstances.add(new MobEffectInstance(effect, 70 + 30 * level, amplifier));
}
projectile.effect(mobEffectInstances);
} }
} }

View file

@ -24,6 +24,7 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
@ -35,6 +36,7 @@ import net.minecraftforge.network.NetworkEvent;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import org.joml.Vector3d; import org.joml.Vector3d;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier; 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); bypassArmorRate += ammoPerk.bypassArmorRate + (perk == ModPerks.AP_BULLET.get() ? 0.05f * (level - 1) : 0);
projectile.setRGB(ammoPerk.rgb); projectile.setRGB(ammoPerk.rgb);
if (ammoPerk.mobEffect.get() != null) { if (!ammoPerk.mobEffects.get().isEmpty()) {
projectile.effect(() -> new MobEffectInstance(ammoPerk.mobEffect.get(), 70 + 30 * level, level - 1)); ArrayList<MobEffectInstance> mobEffectInstances = new ArrayList<>();
for (MobEffect effect : ammoPerk.mobEffects.get()) {
mobEffectInstances.add(new MobEffectInstance(effect, 70 + 30 * level, level - 1));
}
projectile.effect(mobEffectInstances);
} }
} }

View file

@ -3,15 +3,17 @@ package com.atsuishio.superbwarfare.perk;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
import java.util.ArrayList;
import java.util.function.Supplier; import java.util.function.Supplier;
public class AmmoPerk extends Perk { public class AmmoPerk extends Perk {
public float bypassArmorRate; public float bypassArmorRate;
public float damageRate; public float damageRate;
public float speedRate; public float speedRate;
public boolean slug; public boolean slug;
public float[] rgb; public float[] rgb;
public Supplier<MobEffect> mobEffect; public Supplier<ArrayList<MobEffect>> mobEffects;
public AmmoPerk(AmmoPerk.Builder builder) { public AmmoPerk(AmmoPerk.Builder builder) {
super(builder.descriptionId, builder.type); super(builder.descriptionId, builder.type);
@ -20,10 +22,11 @@ public class AmmoPerk extends Perk {
this.speedRate = builder.speedRate; this.speedRate = builder.speedRate;
this.slug = builder.slug; this.slug = builder.slug;
this.rgb = builder.rgb; this.rgb = builder.rgb;
this.mobEffect = builder.mobEffect; this.mobEffects = () -> builder.mobEffects;
} }
public static class Builder { public static class Builder {
String descriptionId; String descriptionId;
Type type; Type type;
float bypassArmorRate = 0.0f; float bypassArmorRate = 0.0f;
@ -31,7 +34,7 @@ public class AmmoPerk extends Perk {
float speedRate = 1.0f; float speedRate = 1.0f;
boolean slug = false; boolean slug = false;
float[] rgb = {1, 222 / 255f, 39 / 255f}; float[] rgb = {1, 222 / 255f, 39 / 255f};
public Supplier<MobEffect> mobEffect = () -> null; public ArrayList<MobEffect> mobEffects = new ArrayList<>();
public Builder(String descriptionId, Type type) { public Builder(String descriptionId, Type type) {
this.descriptionId = descriptionId; this.descriptionId = descriptionId;
@ -66,7 +69,7 @@ public class AmmoPerk extends Perk {
} }
public AmmoPerk.Builder mobEffect(Supplier<MobEffect> mobEffect) { public AmmoPerk.Builder mobEffect(Supplier<MobEffect> mobEffect) {
this.mobEffect = mobEffect; this.mobEffects.add(mobEffect.get());
return this; return this;
} }
} }