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 a2335ae commit c3289c0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
Expand Down Expand Up @@ -91,6 +92,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)
IHasCustomizableAttributes.applyAttributesForEntity(type, this);
this.lookHelper = new IAFLookHelper(this);
this.noCulling = true;
Expand All @@ -115,14 +117,19 @@ public EntityDeathWorm(EntityType<EntityDeathWorm> type, Level worldIn) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ public void containerChanged(Container pInvBasic) {

}

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

Expand All @@ -933,13 +934,13 @@ public SwimmingMoveHelper() {
@Override
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));
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,6 +1,7 @@
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.world.entity.LivingEntity;
import net.minecraft.world.entity.PathfinderMob;
Expand All @@ -23,8 +24,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 +37,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 @@ -2,6 +2,7 @@

import com.github.alexthe666.iceandfire.entity.EntityDeathWorm;
import net.minecraft.core.BlockPos;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.ai.navigation.WaterBoundPathNavigation;
import net.minecraft.world.level.BlockGetter;
Expand Down Expand Up @@ -53,16 +54,16 @@ protected boolean canUpdatePath() {
return new Vec3(this.mob.getX(), this.mob.getY() + 0.5D, this.mob.getZ());
}

@Override
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));

/**
* Checks if the specified entity can safely walk to the specified location.
*/
protected boolean canMoveDirectly(Vec3 posVec31, Vec3 posVec32, int sizeX, int sizeY, int sizeZ) {
HitResult raytraceresult = this.level.clip(new CustomRayTraceContext(posVec31, posVec32, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mob));
if (raytraceresult != null && raytraceresult.getType() == HitResult.Type.BLOCK) {
return mob.level.getBlockState(new BlockPos(raytraceresult.getLocation())).getMaterial() == Material.SAND;
if (raytraceresult.getType() == HitResult.Type.BLOCK) {
Vec3 vec3i = raytraceresult.getLocation();
return mob.level.getBlockState(new BlockPos(vec3i)).is(BlockTags.SAND);
}
return false;

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

@Override
Expand Down

0 comments on commit c3289c0

Please sign in to comment.