添加怪物猎人伤害适配
This commit is contained in:
parent
be4c9cd8cc
commit
590e20e047
3 changed files with 30 additions and 19 deletions
|
@ -36,7 +36,7 @@ import java.util.Optional;
|
|||
|
||||
public class GunGrenadeEntity extends ThrowableItemProjectile {
|
||||
|
||||
private int monster_multiple = 0;
|
||||
private int monsterMultiplier = 0;
|
||||
private float damage = 5f;
|
||||
|
||||
public GunGrenadeEntity(EntityType<? extends GunGrenadeEntity> type, Level world) {
|
||||
|
@ -47,10 +47,10 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
super(type, entity, world);
|
||||
}
|
||||
|
||||
public GunGrenadeEntity(LivingEntity entity, Level level, float damage, int monster_multiple) {
|
||||
public GunGrenadeEntity(LivingEntity entity, Level level, float damage, int monsterMultiplier) {
|
||||
super(TargetModEntities.GUN_GRENADE.get(), entity, level);
|
||||
this.damage = damage;
|
||||
this.monster_multiple = monster_multiple;
|
||||
this.monsterMultiplier = monsterMultiplier;
|
||||
}
|
||||
|
||||
public GunGrenadeEntity(PlayMessages.SpawnEntity spawnEntity, Level level) {
|
||||
|
@ -69,7 +69,7 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
|
||||
@Override
|
||||
protected void onHitEntity(EntityHitResult result) {
|
||||
float m_multiple = (1 + 0.4f * this.monster_multiple);
|
||||
float damageMultiplier = 1 + 0.4f * this.monsterMultiplier;
|
||||
Entity entity = result.getEntity();
|
||||
if (this.getOwner() instanceof LivingEntity living) {
|
||||
if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
|
||||
|
@ -128,13 +128,13 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
|
||||
if (headshot) {
|
||||
if (entity instanceof Monster monster) {
|
||||
monster.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * 2f * m_multiple);
|
||||
monster.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * 2f * damageMultiplier);
|
||||
} else {
|
||||
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * 2f);
|
||||
}
|
||||
} else {
|
||||
if (entity instanceof Monster monster) {
|
||||
monster.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * m_multiple);
|
||||
monster.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage * damageMultiplier);
|
||||
} else {
|
||||
entity.hurt(TargetModDamageTypes.causeGunFireHeadshotDamage(this.level().registryAccess(), this, this.getOwner()), this.damage);
|
||||
}
|
||||
|
@ -176,8 +176,8 @@ public class GunGrenadeEntity extends ThrowableItemProjectile {
|
|||
|
||||
private void causeExplode() {
|
||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 72f, this.getX(), this.getY(), this.getZ(),
|
||||
7.5f, Explosion.BlockInteraction.KEEP);
|
||||
TargetModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), 72f,
|
||||
this.getX(), this.getY(), this.getZ(), 7.5f, Explosion.BlockInteraction.KEEP).setDamageMultiplier(this.monsterMultiplier);
|
||||
explosion.explode();
|
||||
net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion);
|
||||
explosion.finalizeExplosion(false);
|
||||
|
|
|
@ -35,9 +35,8 @@ public class M79fireProcedure {
|
|||
|
||||
Level level = entity.level();
|
||||
if (!level.isClientSide()) {
|
||||
|
||||
int monster_multiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), stack);
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage"), monster_multiple);
|
||||
int monsterMultiple = EnchantmentHelper.getTagEnchantmentLevel(TargetModEnchantments.MONSTER_HUNTER.get(), stack);
|
||||
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, level, (float) stack.getOrCreateTag().getDouble("damage"), monsterMultiple);
|
||||
|
||||
gunGrenadeEntity.setPos(entity.getX(), entity.getEyeY() - 0.1, entity.getZ());
|
||||
gunGrenadeEntity.shoot(entity.getLookAngle().x, entity.getLookAngle().y, entity.getLookAngle().z, (float) stack.getOrCreateTag().getDouble("velocity"),
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.world.damagesource.DamageSource;
|
|||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.PrimedTnt;
|
||||
import net.minecraft.world.entity.monster.Monster;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
|
@ -34,10 +35,11 @@ public class CustomExplosion extends Explosion {
|
|||
private final DamageSource damageSource;
|
||||
private final ExplosionDamageCalculator damageCalculator;
|
||||
private final float damage;
|
||||
private final int fireTime;
|
||||
private int fireTime;
|
||||
private float damageMultiplier;
|
||||
|
||||
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, @Nullable ExplosionDamageCalculator pDamageCalculator,
|
||||
float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, int fireTime,
|
||||
float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius,
|
||||
Explosion.BlockInteraction pBlockInteraction) {
|
||||
super(pLevel, pSource, source, null, pToBlowX, pToBlowY, pToBlowZ, pRadius, false, pBlockInteraction);
|
||||
this.level = pLevel;
|
||||
|
@ -49,19 +51,24 @@ public class CustomExplosion extends Explosion {
|
|||
this.y = pToBlowY;
|
||||
this.z = pToBlowZ;
|
||||
this.damage = damage;
|
||||
this.fireTime = fireTime;
|
||||
}
|
||||
|
||||
public CustomExplosion(Level pLevel, @Nullable Entity pSource, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, Explosion.BlockInteraction pBlockInteraction) {
|
||||
this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, 0, pBlockInteraction);
|
||||
this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction);
|
||||
}
|
||||
|
||||
public CustomExplosion(Level pLevel, @Nullable Entity pSource, @Nullable DamageSource source, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, Explosion.BlockInteraction pBlockInteraction) {
|
||||
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, 0, pBlockInteraction);
|
||||
this(pLevel, pSource, source, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, pBlockInteraction);
|
||||
}
|
||||
|
||||
public CustomExplosion(Level pLevel, @Nullable Entity pSource, float damage, double pToBlowX, double pToBlowY, double pToBlowZ, float pRadius, int fireTime, Explosion.BlockInteraction pBlockInteraction) {
|
||||
this(pLevel, pSource, null, null, damage, pToBlowX, pToBlowY, pToBlowZ, pRadius, fireTime, pBlockInteraction);
|
||||
public CustomExplosion setFireTime(int fireTime) {
|
||||
this.fireTime = fireTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CustomExplosion setDamageMultiplier(float damageMultiplier) {
|
||||
this.damageMultiplier = damageMultiplier;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,7 +146,12 @@ public class CustomExplosion extends Explosion {
|
|||
double seenPercent = getSeenPercent(position, entity);
|
||||
double damagePercent = (1.0D - distanceRate) * seenPercent;
|
||||
|
||||
entity.hurt(this.damageSource, (float) ((int) ((damagePercent * damagePercent + damagePercent) / 2.0D * damage)));
|
||||
double damageFinal = (damagePercent * damagePercent + damagePercent) / 2.0D * damage;
|
||||
if (entity instanceof Monster monster) {
|
||||
monster.hurt(this.damageSource, (int) damageFinal * (1 + 0.4f * this.damageMultiplier));
|
||||
} else {
|
||||
entity.hurt(this.damageSource, (float) ((int) damageFinal));
|
||||
}
|
||||
|
||||
if (fireTime > 0) {
|
||||
entity.setSecondsOnFire(fireTime);
|
||||
|
|
Loading…
Add table
Reference in a new issue