提取其他实体的伤害减免计算

This commit is contained in:
Light_Quanta 2025-06-23 02:46:52 +08:00
parent 0aee8d49cd
commit 00fff469be
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
12 changed files with 100 additions and 208 deletions

View file

@ -10,7 +10,6 @@ import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -114,14 +113,8 @@ public class VehicleData {
var modifier = new DamageModifier();
if (data.applyDefaultDamageModifiers) {
modifier.immuneTo(EntityType.POTION)
.immuneTo(EntityType.AREA_EFFECT_CLOUD)
.immuneTo(DamageTypes.FALL)
.immuneTo(DamageTypes.DROWN)
.immuneTo(DamageTypes.DRAGON_BREATH)
.immuneTo(DamageTypes.WITHER)
.immuneTo(DamageTypes.WITHER_SKULL)
.reduce(5, ModDamageTypes.VEHICLE_STRIKE);
modifier.addAll(DamageModifier.createDefaultModifier().toList());
modifier.reduce(5, ModDamageTypes.VEHICLE_STRIKE);
}
return modifier.addAll(data.damageModifiers);

View file

@ -1,5 +1,6 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
@ -21,7 +22,6 @@ import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
@ -71,25 +71,15 @@ public class Blu43Entity extends Entity implements GeoEntity, OwnableEntity {
return !this.isRemoved();
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.multiply(0.02f, ModDamageTypes.CUSTOM_EXPLOSION)
.multiply(0.02f, ModDamageTypes.MINE)
.multiply(0.02f, ModDamageTypes.PROJECTILE_BOOM)
.multiply(0.02f, DamageTypes.EXPLOSION);
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(DamageTypes.EXPLOSION)) {
amount *= 0.02f;
}
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());
}

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
@ -18,10 +19,8 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -71,25 +70,14 @@ public class ClaymoreEntity extends Entity implements GeoEntity, OwnableEntity {
return !this.isRemoved();
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.multiply(0.2f, ModDamageTypes.CUSTOM_EXPLOSION)
.multiply(0.2f, ModDamageTypes.MINE)
.multiply(0.2f, ModDamageTypes.PROJECTILE_BOOM);
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM)) {
amount *= 0.2f;
}
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.FormatTool;
@ -21,7 +22,6 @@ import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
@ -77,21 +77,15 @@ public class TargetEntity extends LivingEntity implements GeoEntity {
return true;
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.immuneTo(DamageTypes.LIGHTNING_BOLT)
.immuneTo(DamageTypes.FALLING_ANVIL)
.immuneTo(DamageTypes.MAGIC);
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.is(DamageTypes.IN_FIRE)
|| source.getDirectEntity() instanceof ThrownPotion
|| source.getDirectEntity() instanceof AreaEffectCloud
|| source.is(DamageTypes.FALL)
|| source.is(DamageTypes.CACTUS)
|| source.is(DamageTypes.DROWN)
|| source.is(DamageTypes.LIGHTNING_BOLT)
|| source.is(DamageTypes.FALLING_ANVIL)
|| source.is(DamageTypes.DRAGON_BREATH)
|| source.is(DamageTypes.WITHER)
|| source.is(DamageTypes.WITHER_SKULL)
|| source.is(DamageTypes.MAGIC)
|| this.entityData.get(DOWN_TIME) > 0) {
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
if (amount <= 0 || this.entityData.get(DOWN_TIME) > 0) {
return false;
}

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
@ -21,7 +22,6 @@ import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -75,25 +75,15 @@ public class Tm62Entity extends Entity implements GeoEntity, OwnableEntity {
return !this.isRemoved();
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.multiply(0.02f, ModDamageTypes.CUSTOM_EXPLOSION)
.multiply(0.02f, ModDamageTypes.MINE)
.multiply(0.02f, ModDamageTypes.PROJECTILE_BOOM)
.multiply(0.02f, DamageTypes.EXPLOSION);
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.is(ModDamageTypes.CUSTOM_EXPLOSION) || source.is(ModDamageTypes.MINE) || source.is(ModDamageTypes.PROJECTILE_BOOM) || source.is(DamageTypes.EXPLOSION)) {
amount *= 0.02f;
}
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());
}

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.*;
@ -19,14 +20,11 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Pig;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -54,7 +52,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
private float explosionDamage = ExplosionConfig.AGM_65_EXPLOSION_DAMAGE.get();
private float explosionRadius = ExplosionConfig.AGM_65_EXPLOSION_RADIUS.get().floatValue();
private boolean distracted = false;
private int durability = 50;
private int durability;
public Agm65Entity(EntityType<? extends Agm65Entity> type, Level world) {
super(type, world);
@ -76,22 +74,12 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
return ModItems.AGM.get();
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier();
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
return super.hurt(source, amount);
@ -278,7 +266,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f));
destroyBlock();
}
@Override
public boolean isNoGravity() {
return true;

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.*;
@ -19,15 +20,12 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Pig;
import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -94,22 +92,11 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
this.entityData.set(TOP, mode);
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier();
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
return super.hurt(source, amount);
@ -362,7 +349,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 0.96, 0.96));
destroyBlock();
}
private PlayState movementPredicate(AnimationState<JavelinMissileEntity> event) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle"));
}

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.tools.ProjectileTool;
import net.minecraft.core.BlockPos;
@ -10,11 +11,8 @@ import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
@ -48,22 +46,11 @@ public class MelonBombEntity extends FastThrowableProjectile implements Explosiv
return true;
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier();
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
return super.hurt(source, amount);

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
@ -12,12 +13,9 @@ import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
@ -56,25 +54,13 @@ public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, Ex
return ModItems.MEDIUM_AERIAL_BOMB.get();
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.immuneTo(ModEntities.MK_82.get());
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.getDirectEntity() instanceof Mk82Entity)
return false;
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
public boolean hurt(@NotNull DamageSource source, float amount) {
var newAmount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - newAmount);
return super.hurt(source, amount);
}

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion;
@ -18,12 +19,9 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
@ -96,25 +94,12 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
this.entityData.set(TARGET_Z, (float) targetPos.z);
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier()
.immuneTo(ModEntities.SWARM_DRONE.get());
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
if (source.getDirectEntity() instanceof SwarmDroneEntity) {
return false;
}
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
return super.hurt(source, amount);

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
@ -22,12 +23,9 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion;
@ -65,22 +63,11 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
this.durability = 50;
}
private static final DamageModifier DAMAGE_MODIFIER = DamageModifier.createDefaultModifier();
@Override
public boolean hurt(DamageSource source, float amount) {
if (source.getDirectEntity() instanceof ThrownPotion || source.getDirectEntity() instanceof AreaEffectCloud)
return false;
if (source.is(DamageTypes.FALL))
return false;
if (source.is(DamageTypes.CACTUS))
return false;
if (source.is(DamageTypes.DROWN))
return false;
if (source.is(DamageTypes.DRAGON_BREATH))
return false;
if (source.is(DamageTypes.WITHER))
return false;
if (source.is(DamageTypes.WITHER_SKULL))
return false;
public boolean hurt(@NotNull DamageSource source, float amount) {
amount = DAMAGE_MODIFIER.compute(source, amount);
this.entityData.set(HEALTH, this.entityData.get(HEALTH) - amount);
return super.hurt(source, amount);
@ -248,7 +235,7 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
}
destroyBlock();
}
private PlayState movementPredicate(AnimationState<WgMissileEntity> event) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle"));
}

View file

@ -4,6 +4,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EntityType;
import java.util.ArrayList;
@ -18,6 +19,18 @@ public class DamageModifier {
private final List<DamageModify> multiplyList = new ArrayList<>();
private final List<BiFunction<DamageSource, Float, Float>> customList = new ArrayList<>();
public static DamageModifier createDefaultModifier() {
return new DamageModifier()
.immuneTo(EntityType.POTION)
.immuneTo(EntityType.AREA_EFFECT_CLOUD)
.immuneTo(DamageTypes.FALL)
.immuneTo(DamageTypes.CACTUS)
.immuneTo(DamageTypes.DROWN)
.immuneTo(DamageTypes.DRAGON_BREATH)
.immuneTo(DamageTypes.WITHER)
.immuneTo(DamageTypes.WITHER_SKULL);
}
/**
* 免疫所有伤害
*/
@ -224,6 +237,17 @@ public class DamageModifier {
return this;
}
public List<DamageModify> toList() {
var list = new ArrayList<DamageModify>();
// 计算优先级 免疫 > 固定减伤 >
list.addAll(immuneList);
list.addAll(reduceList);
list.addAll(multiplyList);
return list;
}
/**
* 计算减伤后的伤害值
*
@ -232,14 +256,7 @@ public class DamageModifier {
* @return 减伤后的伤害值
*/
public float compute(DamageSource source, float damage) {
var list = new ArrayList<DamageModify>();
// 计算优先级 免疫 > 固定减伤 >
list.addAll(immuneList);
list.addAll(reduceList);
list.addAll(multiplyList);
for (DamageModify damageModify : list) {
for (DamageModify damageModify : toList()) {
if (damageModify.match(source)) {
damage = damageModify.compute(damage);