实现防御塔简易敌我区分
This commit is contained in:
parent
9c071e4767
commit
1623994578
3 changed files with 60 additions and 5 deletions
|
@ -264,6 +264,10 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID));
|
Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID));
|
||||||
|
|
||||||
if (target != null && this.getOwner() instanceof Player player && smokeFilter(target)) {
|
if (target != null && this.getOwner() instanceof Player player && smokeFilter(target)) {
|
||||||
|
if (target instanceof Player player1 && (player1.isSpectator() || player1.isCreative())) {
|
||||||
|
this.entityData.set(TARGET_UUID, "none");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (target.distanceTo(this) > 160) {
|
if (target.distanceTo(this) > 160) {
|
||||||
this.entityData.set(TARGET_UUID, "none");
|
this.entityData.set(TARGET_UUID, "none");
|
||||||
return;
|
return;
|
||||||
|
@ -281,7 +285,11 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ()).add(target.getDeltaMovement().scale((4 + 0.025 * target.distanceTo(this)) * random.nextFloat() * 0.2f + 1));
|
if (target.getVehicle() != null) {
|
||||||
|
this.entityData.set(TARGET_UUID, target.getVehicle().getStringUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 4, target.getZ()).add(target.getDeltaMovement().scale((1 * (random.nextFloat() * 0.1f + 1) + 0.05 * target.distanceTo(this))));
|
||||||
Vec3 targetVec = barrelRootPos.vectorTo(targetPos).normalize();
|
Vec3 targetVec = barrelRootPos.vectorTo(targetPos).normalize();
|
||||||
|
|
||||||
double d0 = targetVec.x;
|
double d0 = targetVec.x;
|
||||||
|
@ -321,6 +329,23 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean basicEnemyFilter(Entity pEntity) {
|
||||||
|
if (pEntity instanceof Projectile) return false;
|
||||||
|
if (this.getOwner() == null) return false;
|
||||||
|
if (pEntity.getTeam() == null) return false;
|
||||||
|
|
||||||
|
return !pEntity.isAlliedTo(this.getOwner()) || (pEntity.getTeam() != null && pEntity.getTeam().getName().equals("TDM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean basicEnemyProjectileFilter(Projectile projectile) {
|
||||||
|
if (this.getOwner() == null) return false;
|
||||||
|
if (projectile.getOwner() == null) return false;
|
||||||
|
if (projectile.getOwner() == this.getOwner()) return false;
|
||||||
|
return !projectile.getOwner().isAlliedTo(this.getOwner()) || (projectile.getOwner().getTeam() != null && projectile.getOwner().getTeam().getName().equals("TDM"));
|
||||||
|
}
|
||||||
|
|
||||||
public void findEntityOnPath(Vec3 pos, Vec3 toVec) {
|
public void findEntityOnPath(Vec3 pos, Vec3 toVec) {
|
||||||
List<Entity> entities = this.level()
|
List<Entity> entities = this.level()
|
||||||
.getEntities(this,
|
.getEntities(this,
|
||||||
|
@ -454,7 +479,7 @@ public class Hpj11Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
Vector4f worldPosition = transformPosition(transform, 0f, 0.4f, 2.6875f);
|
Vector4f worldPosition = transformPosition(transform, 0f, 0.4f, 2.6875f);
|
||||||
|
|
||||||
entityToSpawn.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
entityToSpawn.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
||||||
entityToSpawn.shoot(getLookAngle().x, getLookAngle().y, getLookAngle().z, 30, 0.5f);
|
entityToSpawn.shoot(getLookAngle().x, getLookAngle().y, getLookAngle().z, 30, 1f);
|
||||||
level().addFreshEntity(entityToSpawn);
|
level().addFreshEntity(entityToSpawn);
|
||||||
|
|
||||||
if (!player.level().isClientSide) {
|
if (!player.level().isClientSide) {
|
||||||
|
|
|
@ -250,6 +250,10 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
||||||
Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID));
|
Entity target = EntityFindUtil.findEntity(level(), entityData.get(TARGET_UUID));
|
||||||
|
|
||||||
if (target != null && smokeFilter(target)) {
|
if (target != null && smokeFilter(target)) {
|
||||||
|
if (target instanceof Player player1 && (player1.isSpectator() || player1.isCreative())) {
|
||||||
|
this.entityData.set(TARGET_UUID, "none");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (target.distanceTo(this) > 72) {
|
if (target.distanceTo(this) > 72) {
|
||||||
this.entityData.set(TARGET_UUID, "none");
|
this.entityData.set(TARGET_UUID, "none");
|
||||||
return;
|
return;
|
||||||
|
@ -324,6 +328,23 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean basicEnemyFilter(Entity pEntity) {
|
||||||
|
if (pEntity instanceof Projectile) return false;
|
||||||
|
if (this.getOwner() == null) return false;
|
||||||
|
if (pEntity.getTeam() == null) return false;
|
||||||
|
|
||||||
|
return !pEntity.isAlliedTo(this.getOwner()) || (pEntity.getTeam() != null && pEntity.getTeam().getName().equals("TDM"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean basicEnemyProjectileFilter(Projectile projectile) {
|
||||||
|
if (this.getOwner() == null) return false;
|
||||||
|
if (projectile.getOwner() == null) return false;
|
||||||
|
if (projectile.getOwner() == this.getOwner()) return false;
|
||||||
|
return !projectile.getOwner().isAlliedTo(this.getOwner()) || (projectile.getOwner().getTeam() != null && projectile.getOwner().getTeam().getName().equals("TDM"));
|
||||||
|
}
|
||||||
|
|
||||||
private void causeAirExplode(Vec3 vec3) {
|
private void causeAirExplode(Vec3 vec3) {
|
||||||
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
CustomExplosion explosion = new CustomExplosion(this.level(), this,
|
||||||
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
|
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
|
||||||
|
|
|
@ -984,7 +984,8 @@ public abstract class VehicleEntity extends Entity {
|
||||||
if (e.distanceTo(this) > minRange
|
if (e.distanceTo(this) > minRange
|
||||||
&& e.distanceTo(this) <= seekRange
|
&& e.distanceTo(this) <= seekRange
|
||||||
&& canAim(pos, e, minAngle, maxAngle)
|
&& canAim(pos, e, minAngle, maxAngle)
|
||||||
&& ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || e == seekThreateningEntity(size, pos))
|
&& !(e instanceof Player player && (player.isSpectator() || player.isCreative()))
|
||||||
|
&& ((e instanceof LivingEntity living && living instanceof Enemy && living.getHealth() > 0) || e == seekThreateningEntity(size, pos) || basicEnemyFilter(e))
|
||||||
&& smokeFilter(e)) {
|
&& smokeFilter(e)) {
|
||||||
return checkNoClip(e, pos);
|
return checkNoClip(e, pos);
|
||||||
}
|
}
|
||||||
|
@ -996,8 +997,8 @@ public abstract class VehicleEntity extends Entity {
|
||||||
public Entity seekThreateningEntity(double size, Vec3 pos) {
|
public Entity seekThreateningEntity(double size, Vec3 pos) {
|
||||||
return StreamSupport.stream(EntityFindUtil.getEntities(level()).getAll().spliterator(), false)
|
return StreamSupport.stream(EntityFindUtil.getEntities(level()).getAll().spliterator(), false)
|
||||||
.filter(e -> {
|
.filter(e -> {
|
||||||
if (!e.onGround() && e instanceof Projectile && (e.getBbWidth() >= size || e.getBbHeight() >= size) && VectorTool.calculateAngle(e.getDeltaMovement().normalize(), e.position().vectorTo(this.position()).normalize()) < 30) {
|
if (!e.onGround() && e instanceof Projectile projectile && (e.getBbWidth() >= size || e.getBbHeight() >= size) && VectorTool.calculateAngle(e.getDeltaMovement().normalize(), e.position().vectorTo(this.position()).normalize()) < 30) {
|
||||||
return checkNoClip(e, pos);
|
return checkNoClip(e, pos) && basicEnemyProjectileFilter(projectile);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null);
|
}).min(Comparator.comparingDouble(e -> e.distanceTo(this))).orElse(null);
|
||||||
|
@ -1009,6 +1010,14 @@ public abstract class VehicleEntity extends Entity {
|
||||||
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK;
|
ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this)).getType() != HitResult.Type.BLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean basicEnemyFilter(Entity pEntity) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean basicEnemyProjectileFilter(Projectile projectile) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean canAim(Vec3 pos, Entity target, double minAngle, double maxAngle) {
|
public static boolean canAim(Vec3 pos, Entity target, double minAngle, double maxAngle) {
|
||||||
Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ());
|
Vec3 targetPos = new Vec3(target.getX(), target.getY() + target.getBbHeight() / 2, target.getZ());
|
||||||
Vec3 toVec = pos.vectorTo(targetPos).normalize();
|
Vec3 toVec = pos.vectorTo(targetPos).normalize();
|
||||||
|
|
Loading…
Add table
Reference in a new issue