添加载具角度减伤/增伤机制
This commit is contained in:
parent
937f8340e9
commit
43829c9b0c
8 changed files with 43 additions and 23 deletions
|
@ -217,6 +217,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
.multiply(0.24f, ModDamageTypes.LUNGE_MINE)
|
||||
.multiply(0.3f, ModDamageTypes.CANNON_FIRE)
|
||||
.multiply(0.04f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 3) * damage)
|
||||
.reduce(12);
|
||||
}
|
||||
|
||||
|
|
|
@ -156,6 +156,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
.multiply(0.1f, ModTags.DamageTypes.PROJECTILE)
|
||||
.multiply(0.7f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.multiply(8.5f, ModDamageTypes.VEHICLE_STRIKE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 0.4f) * damage)
|
||||
.reduce(8);
|
||||
}
|
||||
|
||||
|
|
|
@ -144,6 +144,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
.multiply(0.25f, ModTags.DamageTypes.PROJECTILE)
|
||||
.multiply(0.85f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.multiply(10f, ModDamageTypes.VEHICLE_STRIKE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 0.25f) * damage)
|
||||
.reduce(7);
|
||||
}
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
|
|||
.multiply(0.25f, ModTags.DamageTypes.PROJECTILE)
|
||||
.multiply(0.85f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.multiply(10f, ModDamageTypes.VEHICLE_STRIKE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 1f) * damage)
|
||||
.reduce(8);
|
||||
}
|
||||
|
||||
|
|
|
@ -213,6 +213,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
|
|||
.multiply(0.25f, ModTags.DamageTypes.PROJECTILE)
|
||||
.multiply(0.85f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.multiply(10f, ModDamageTypes.VEHICLE_STRIKE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 1f) * damage)
|
||||
.reduce(8);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.entity.vehicle;
|
|||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
|
||||
import com.atsuishio.superbwarfare.config.server.VehicleConfig;
|
||||
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity;
|
||||
import com.atsuishio.superbwarfare.entity.vehicle.base.ThirdPersonCameraPosition;
|
||||
|
@ -181,8 +182,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
.multiply(0.75f, ModDamageTypes.PROJECTILE_BOOM)
|
||||
.multiply(0.5f, ModDamageTypes.MINE)
|
||||
.multiply(0.5f, ModDamageTypes.LUNGE_MINE)
|
||||
.multiply(0.95f, ModDamageTypes.CANNON_FIRE)
|
||||
.multiply(1.5f, ModDamageTypes.CANNON_FIRE)
|
||||
.multiply(0.15f, ModTags.DamageTypes.PROJECTILE_ABSOLUTE)
|
||||
.custom((source, damage) -> getSourceAngle(source, 1.5f) * damage)
|
||||
.custom((source, damage) -> {
|
||||
if (source.getDirectEntity() instanceof SmallCannonShellEntity) {
|
||||
return 0.375f * damage;
|
||||
}
|
||||
return damage;
|
||||
})
|
||||
.reduce(9);
|
||||
}
|
||||
|
||||
|
|
|
@ -434,6 +434,20 @@ public abstract class VehicleEntity extends Entity {
|
|||
.reduce(5, ModDamageTypes.VEHICLE_STRIKE);
|
||||
}
|
||||
|
||||
public float getSourceAngle(DamageSource source, float multiply) {
|
||||
Entity attacker = source.getDirectEntity();
|
||||
if (attacker == null) {
|
||||
attacker = source.getEntity();
|
||||
}
|
||||
|
||||
if (attacker != null) {
|
||||
float angle = (float) java.lang.Math.abs(VectorTool.calculateAngle(this.position().vectorTo(attacker.position()), this.getViewVector(1)));
|
||||
return java.lang.Math.max(1f + multiply * ((angle - 90) / 90), 0.5f);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void heal(float pHealAmount) {
|
||||
if (this.level() instanceof ServerLevel) {
|
||||
this.setHealth(this.getHealth() + pHealAmount);
|
||||
|
|
|
@ -6,7 +6,6 @@ import net.minecraft.world.entity.Entity;
|
|||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.ProjectileUtil;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.*;
|
||||
|
||||
public class TraceTool {
|
||||
|
@ -65,38 +64,28 @@ public class TraceTool {
|
|||
|
||||
public static Entity laserfindLookingEntity(Entity player, double entityReach) {
|
||||
|
||||
BlockHitResult blockResult = player.level().clip(
|
||||
new ClipContext(player.getEyePosition(), player.getEyePosition().add(player.getViewVector(1f).scale(512)),
|
||||
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
|
||||
|
||||
BlockPos resultPos = blockResult.getBlockPos();
|
||||
BlockState state = player.level().getBlockState(resultPos);
|
||||
|
||||
double distance = entityReach * entityReach;
|
||||
Vec3 eyePos = player.getEyePosition(1.0f);
|
||||
HitResult hitResult = player.pick(entityReach, 1.0f, false);
|
||||
if (hitResult.getType() != HitResult.Type.MISS) {
|
||||
distance = hitResult.getLocation().distanceToSqr(eyePos);
|
||||
double blockReach = 5;
|
||||
if (distance > blockReach * blockReach) {
|
||||
Vec3 pos = hitResult.getLocation();
|
||||
hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos));
|
||||
}
|
||||
}
|
||||
// if (hitResult.getType() != HitResult.Type.MISS) {
|
||||
// distance = hitResult.getLocation().distanceToSqr(eyePos);
|
||||
// double blockReach = 5;
|
||||
// if (distance > blockReach * blockReach) {
|
||||
// Vec3 pos = hitResult.getLocation();
|
||||
// hitResult = BlockHitResult.miss(pos, Direction.getNearest(eyePos.x, eyePos.y, eyePos.z), BlockPos.containing(pos));
|
||||
// }
|
||||
// }
|
||||
|
||||
Vec3 viewVec = player.getViewVector(1.0F);
|
||||
Vec3 toVec = eyePos.add(viewVec.x * entityReach, viewVec.y * entityReach, viewVec.z * entityReach);
|
||||
AABB aabb = player.getBoundingBox().expandTowards(viewVec.scale(entityReach)).inflate(1.0D, 1.0D, 1.0D);
|
||||
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(player, eyePos, toVec, aabb, p -> !p.isSpectator() && player.getVehicle() != p && p.isAlive(), distance);
|
||||
if (entityhitresult != null) {
|
||||
Vec3 targetPos = entityhitresult.getLocation();
|
||||
double distanceToTarget = eyePos.distanceToSqr(targetPos);
|
||||
if (distanceToTarget > distance || distanceToTarget > entityReach * entityReach) {
|
||||
hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos));
|
||||
} else if (distanceToTarget < distance) {
|
||||
Vec3 hitVec = entityhitresult.getLocation();
|
||||
if (checkNoClip(player, hitVec)) {
|
||||
hitResult = entityhitresult;
|
||||
}
|
||||
Vec3 hitVec = entityhitresult.getLocation();
|
||||
|
||||
if (hitResult.getType() == HitResult.Type.ENTITY && ((EntityHitResult) hitResult).getEntity().isAlive()) {
|
||||
if (((EntityHitResult) hitResult).getEntity() instanceof LivingEntity living) {
|
||||
laserHeadshot = living.getEyeY() - 0.4 < hitVec.y && hitVec.y < living.getEyeY() + 0.5;
|
||||
|
@ -109,4 +98,8 @@ public class TraceTool {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean checkNoClip(Entity entity, Vec3 target) {
|
||||
return entity.level().clip(new ClipContext(entity.getEyePosition(), target, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity)).getType() != HitResult.Type.BLOCK;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue