Skip to content

Commit

Permalink
fix: pathing and target problems with death worms
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX authored and TheBv committed Dec 26, 2023
1 parent 9bdd8fc commit dd4eb25
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.common.MinecraftForge;
Expand Down Expand Up @@ -96,6 +97,7 @@ public class EntityDeathWorm extends TamableAnimal implements ISyncMount, ICusto

public EntityDeathWorm(EntityType<EntityDeathWorm> type, Level worldIn) {
super(type, worldIn);
setPathfindingMalus(BlockPathTypes.OPEN, 2.0f); // FIXME :: Death worms are trying to go upwards -> figure out why (or if this really helps)
this.lookHelper = new IAFLookHelper(this);
this.noCulling = true;
if (worldIn.isClientSide) {
Expand Down Expand Up @@ -123,14 +125,19 @@ protected void registerGoals() {
public boolean apply(@Nullable LivingEntity input) {
if (EntityDeathWorm.this.isTame()) {
return input instanceof Monster;
} else {
return (IafConfig.deathWormAttackMonsters ?
input instanceof LivingEntity && DragonUtils.isAlive(input) && !input.isInWater() :
(input instanceof Animal || input instanceof Player)) &&
DragonUtils.isAlive(input) && !(input instanceof EntityDragonBase &&
((EntityDragonBase) input).isModelDead()) && !EntityDeathWorm.this.isOwnedBy(input)
&& !input.isInWater();
} else if (input != null) {
if (input.isInWater() || !DragonUtils.isAlive(input) || isOwnedBy(input)) {
return false;
}

if (input instanceof Player || input instanceof Animal) {
return true;
}

return IafConfig.deathWormAttackMonsters;
}

return false;
}
}));
}
Expand Down Expand Up @@ -670,7 +677,7 @@ public void tick() {
refreshDimensions();
onUpdateParts();
if (this.attack() && this.getControllingPassenger() != null && this.getControllingPassenger() instanceof Player) {
LivingEntity target = DragonUtils.riderLookingAtEntity(this, (Player) this.getControllingPassenger(), 3);
LivingEntity target = DragonUtils.riderLookingAtEntity(this, this.getControllingPassenger(), 3);
if (this.getAnimation() != ANIMATION_BITE) {
this.setAnimation(ANIMATION_BITE);
this.playSound(this.getScale() > 3 ? IafSoundRegistry.DEATHWORM_GIANT_ATTACK : IafSoundRegistry.DEATHWORM_ATTACK, 1, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public Player getRidingPlayer() {
}

public double getRideSpeedModifier() {
return this.isInWater() ? 1f * IafConfig.hippocampusSwimSpeedMod : 0.55F;
return this.isInWater() ? 0.75f * IafConfig.hippocampusSwimSpeedMod : 0.2f;
}

public int getInventoryColumns() {
Expand All @@ -811,6 +811,7 @@ public void containerChanged(Container pInvBasic) {

}

/** Only called Server side */
class SwimmingMoveHelper extends MoveControl {
private final EntityHippocampus hippo = EntityHippocampus.this;

Expand All @@ -819,22 +820,20 @@ public SwimmingMoveHelper() {
}

@Override
public void tick() { // FIXME
public void tick() {
if (this.hippo.isVehicle()) {
/*
double flySpeed = hippo.getRideSpeedModifier() * this.hippo.getAttributeValue(Attributes.MOVEMENT_SPEED);
Vec3 dragonVec = hippo.position();
Vec3 moveVec = new Vec3(wantedX, wantedY, wantedZ);
Vec3 normalized = moveVec.subtract(dragonVec).normalize();
double dist = dragonVec.distanceTo(moveVec);
hippo.setDeltaMovement(normalized.x * flySpeed, normalized.y * flySpeed, normalized.z * flySpeed);
if (dist > 2.5E-7) {
double speed = hippo.getRideSpeedModifier() * this.hippo.getAttributeValue(Attributes.MOVEMENT_SPEED);
Vec3 position = hippo.position();
Vec3 targetPosition = new Vec3(wantedX, wantedY, wantedZ);
Vec3 normalized = targetPosition.subtract(position).normalize();
double distance = position.distanceTo(targetPosition);
hippo.setDeltaMovement(normalized.x * speed, normalized.y * speed, normalized.z * speed);
if (distance > 2.5E-7) {
float yaw = (float) Math.toDegrees(Math.PI * 2 - Math.atan2(normalized.x, normalized.y));
hippo.setYRot(rotlerp(hippo.getYRot(), yaw, 5));
hippo.setSpeed((float) (speedModifier));
}
hippo.move(MoverType.SELF, hippo.getDeltaMovement());
*/
} else if (this.operation == MoveControl.Operation.MOVE_TO && !this.hippo.getNavigation().isDone()) {
double distanceX = this.wantedX - this.hippo.getX();
double distanceY = this.wantedY - this.hippo.getY();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public DeathWormAIFindSandTarget(EntityDeathWorm mob, int range) {

@Override
public boolean canUse() {
if (this.mob.getTarget() != null) {
return false;
}

if (!this.mob.isInSand() || this.mob.isPassenger() || this.mob.isVehicle()) {
return false;
}
Expand All @@ -34,7 +38,7 @@ public boolean canUse() {
*/) {
this.mob.getNavigation().stop();
}
if (this.mob.getNavigation().isDone() && !this.mob.getMoveControl().hasWanted()) {
if (this.mob.getNavigation().isDone() /* && !this.mob.getMoveControl().hasWanted()*/) {
BlockPos vec3 = this.findSandTarget();
if (vec3 != null) {
this.mob.getMoveControl().setWantedPosition(vec3.getX(), vec3.getY(), vec3.getZ(), 1.0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.alexthe666.iceandfire.entity.ai;

import com.github.alexthe666.iceandfire.entity.EntityDeathWorm;
import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
import com.google.common.base.Predicate;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
Expand All @@ -23,8 +25,9 @@ public DeathWormAITarget(EntityDeathWorm entityIn, Class<T> classTarget, boolean

@Override
public boolean canUse() {
if (super.canUse() && target != null
&& !target.getClass().isAssignableFrom(this.deathworm.getClass())) {
boolean canUse = super.canUse();

if (canUse && target != null && target.getType() != (IafEntityRegistry.DEATH_WORM.get())) {
if (target instanceof Player && !deathworm.isOwnedBy(target)) {
return !deathworm.isTame();
} else if (deathworm.isOwnedBy(target)) {
Expand All @@ -35,14 +38,17 @@ public boolean canUse() {
if (target instanceof PathfinderMob) {
return deathworm.getWormAge() > 3;
}

return true;
}
}

return false;
}

@Override
protected @NotNull AABB getTargetSearchArea(double targetDistance) {
return this.deathworm.getBoundingBox().inflate(targetDistance, targetDistance, targetDistance);
// Increasing the y-range too much makes it target entities in caves etc., which will be unreachable (thus no target will be set)
return this.deathworm.getBoundingBox().inflate(targetDistance, 6, targetDistance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ protected boolean canUpdatePath() {
}

@Override
protected boolean canMoveDirectly(Vec3 posVec31, Vec3 posVec32) {
HitResult raytraceresult = this.level.clip(new CustomRayTraceContext(posVec31, posVec32, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mob));
if (raytraceresult != null && raytraceresult.getType() == HitResult.Type.BLOCK) {
protected boolean canMoveDirectly(@NotNull final Vec3 start, @NotNull final Vec3 end) {
HitResult raytraceresult = this.level.clip(new CustomRayTraceContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mob));

if (raytraceresult.getType() == HitResult.Type.BLOCK) {
Vec3 vec3i = raytraceresult.getLocation();
return mob.level().getBlockState(BlockPos.containing(vec3i)).is(BlockTags.SAND);
}
return false;

return raytraceresult.getType() == HitResult.Type.MISS;
}

@Override
Expand Down

0 comments on commit dd4eb25

Please sign in to comment.