diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AquaticJumpGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AquaticJumpGoal.java new file mode 100644 index 00000000..2b1606b4 --- /dev/null +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AquaticJumpGoal.java @@ -0,0 +1,110 @@ +package com.spectrobes.spectrobesmod.common.entities.goals; + +import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntityAquaticSpectrobe; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ai.goal.JumpGoal; +import net.minecraft.entity.passive.DolphinEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.Direction; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; + +public class AquaticJumpGoal extends JumpGoal { + private static final int[] STEPS_TO_CHECK = new int[]{0, 1, 4, 5, 6, 7}; + private final EntityAquaticSpectrobe spectrobe; + private final int interval; + private boolean breached; + + public AquaticJumpGoal(EntityAquaticSpectrobe p_i50329_1_, int p_i50329_2_) { + this.spectrobe = p_i50329_1_; + this.interval = p_i50329_2_; + } + + /** + * Returns whether execution should begin. You can also read and cache any state necessary for execution in this + * method as well. + */ + public boolean canUse() { + if (this.spectrobe.getRandom().nextInt(this.interval) != 0) { + return false; + } else { + Direction direction = this.spectrobe.getMotionDirection(); + int i = direction.getStepX(); + int j = direction.getStepZ(); + BlockPos blockpos = this.spectrobe.blockPosition(); + + for(int k : STEPS_TO_CHECK) { + if (!this.waterIsClear(blockpos, i, j, k) || !this.surfaceIsClear(blockpos, i, j, k)) { + return false; + } + } + + return true; + } + } + + private boolean waterIsClear(BlockPos pPos, int pDx, int pDz, int pScale) { + BlockPos blockpos = pPos.offset(pDx * pScale, 0, pDz * pScale); + return this.spectrobe.level.getFluidState(blockpos).is(FluidTags.WATER) && !this.spectrobe.level.getBlockState(blockpos).getMaterial().blocksMotion(); + } + + private boolean surfaceIsClear(BlockPos pPos, int pDx, int pDz, int pScale) { + return this.spectrobe.level.getBlockState(pPos.offset(pDx * pScale, 1, pDz * pScale)).isAir() && this.spectrobe.level.getBlockState(pPos.offset(pDx * pScale, 2, pDz * pScale)).isAir(); + } + + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ + public boolean canContinueToUse() { + double d0 = this.spectrobe.getDeltaMovement().y; + return (!(d0 * d0 < (double)0.03F) || this.spectrobe.xRot == 0.0F || !(Math.abs(this.spectrobe.xRot) < 10.0F) || !this.spectrobe.isInWater()) && !this.spectrobe.isOnGround(); + } + + public boolean isInterruptable() { + return false; + } + + /** + * Execute a one shot task or start executing a continuous task + */ + public void start() { + Direction direction = this.spectrobe.getMotionDirection(); + this.spectrobe.setDeltaMovement(this.spectrobe.getDeltaMovement().add((double)direction.getStepX() * 0.6D, 0.7D, (double)direction.getStepZ() * 0.6D)); + this.spectrobe.getNavigation().stop(); + } + + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ + public void stop() { + this.spectrobe.xRot = 0.0F; + } + + /** + * Keep ticking a continuous task that has already been started + */ + public void tick() { + boolean flag = this.breached; + if (!flag) { + FluidState fluidstate = this.spectrobe.level.getFluidState(this.spectrobe.blockPosition()); + this.breached = fluidstate.is(FluidTags.WATER); + } + + if (this.breached && !flag) { + this.spectrobe.playSound(SoundEvents.DOLPHIN_JUMP, 1.0F, 1.0F); + } + + Vector3d vector3d = this.spectrobe.getDeltaMovement(); + if (vector3d.y * vector3d.y < (double)0.03F && this.spectrobe.xRot != 0.0F) { + this.spectrobe.xRot = MathHelper.rotlerp(this.spectrobe.xRot, 0.0F, 0.2F); + } else { + double d0 = Math.sqrt(Entity.getHorizontalDistanceSqr(vector3d)); + double d1 = Math.signum(-vector3d.y) * Math.acos(d0 / vector3d.length()) * (double)(180F / (float)Math.PI); + this.spectrobe.xRot = (float)d1; + } + + } +} diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AttackKrawlGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AttackKrawlGoal.java index bc164019..baffd5d8 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AttackKrawlGoal.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AttackKrawlGoal.java @@ -1,12 +1,15 @@ package com.spectrobes.spectrobesmod.common.entities.goals; +import com.spectrobes.spectrobesmod.SpectrobesInfo; import com.spectrobes.spectrobesmod.common.entities.krawl.EntityKrawl; +import com.spectrobes.spectrobesmod.common.entities.krawl.EntityVortex; import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties; import net.minecraft.entity.MobEntity; import net.minecraft.entity.ai.goal.TargetGoal; import java.util.List; +import java.util.stream.Collectors; public class AttackKrawlGoal extends TargetGoal { EntityKrawl target; @@ -27,9 +30,10 @@ public boolean canUse() { if(mob instanceof EntitySpectrobe && ((EntitySpectrobe)mob).getStage() == SpectrobeProperties.Stage.CHILD) return false; - List nearbyMobs = mob.level.getEntitiesOfClass(EntityKrawl.class, mob.getBoundingBox().inflate(20, 20, 20)); - if (!nearbyMobs.isEmpty()) { - this.target = nearbyMobs.get(0); + List nearbyMobs = mob.level.getEntitiesOfClass(EntityKrawl.class, mob.getBoundingBox().inflate(5, 5, 5)); + List nonVortexKrawl = nearbyMobs.stream().filter(entityKrawl -> !entityKrawl.isVortex()).collect(Collectors.toList()); + if (!nonVortexKrawl.isEmpty()) { + this.target = nonVortexKrawl.get(0); return true; } return false; @@ -46,11 +50,20 @@ public boolean canContinueToUse() { } } + @Override + public void tick() { + super.tick(); + this.mob.setTarget(this.target); + ((EntitySpectrobe)this.mob).setIsAttacking(true); + this.mob.getMoveControl().setWantedPosition(this.target.getX(), this.target.getY(), this.target.getZ(), 5); + this.mob.setAggressive(true); + } + @Override public void start() { this.mob.setTarget(this.target); ((EntitySpectrobe)this.mob).setIsAttacking(true); - this.mob.getNavigation().moveTo(this.mob.getNavigation().createPath(this.target, 5), 5); + this.mob.getMoveControl().setWantedPosition(this.target.getX(), this.target.getY(), this.target.getZ(), 5); this.mob.setAggressive(true); super.start(); } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AvoidKrawlGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AvoidKrawlGoal.java new file mode 100644 index 00000000..c5b9ea46 --- /dev/null +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/AvoidKrawlGoal.java @@ -0,0 +1,17 @@ +package com.spectrobes.spectrobesmod.common.entities.goals; + +import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; +import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties; +import net.minecraft.entity.CreatureEntity; +import net.minecraft.entity.ai.goal.AvoidEntityGoal; + +public class AvoidKrawlGoal extends AvoidEntityGoal { + public AvoidKrawlGoal(CreatureEntity entity, Class toAvoid, float maxDist, double walkSpeedModifier, double sprintSpeedModifier) { + super(entity, toAvoid, maxDist, walkSpeedModifier, sprintSpeedModifier); + } + + @Override + public boolean canUse() { + return ((EntitySpectrobe)mob).getStage() == SpectrobeProperties.Stage.CHILD && super.canUse(); + } +} diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FightGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FightGoal.java deleted file mode 100644 index e6a11fbd..00000000 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FightGoal.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.spectrobes.spectrobesmod.common.entities.goals; - -import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; -import net.minecraft.entity.CreatureEntity; -import net.minecraft.entity.ai.goal.MeleeAttackGoal; - -public class FightGoal extends MeleeAttackGoal { - public FightGoal(CreatureEntity creature, double speedIn, boolean useLongMemory) { - super(creature, speedIn, useLongMemory); - } - - @Override - public boolean canContinueToUse() { - boolean shouldContinue = super.canContinueToUse(); - - if(shouldContinue) { - ((EntitySpectrobe)this.mob).setIsAttacking(true); - } else { - ((EntitySpectrobe)this.mob).setIsAttacking(false); - } - - return shouldContinue; - } - - @Override - public void start() { - super.start(); - } -} diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindFossilsGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindFossilsGoal.java index 86f0456e..dbef83b0 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindFossilsGoal.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindFossilsGoal.java @@ -12,28 +12,27 @@ public class FindFossilsGoal extends Goal { - private IWorldReader world; private EntitySpectrobe entity; private BlockPos target; public FindFossilsGoal(EntitySpectrobe spectrobe) { this.entity = spectrobe; - this.world = spectrobe.level; } + @Override public boolean canUse() { if(entity.getStage() == SpectrobeProperties.Stage.CHILD && entity.isSearching()) { - List lvt_1_1_ = getFossilBlocksInArea(); - return !lvt_1_1_.isEmpty(); + List blocks = getFossilBlocksInArea(); + return !blocks.isEmpty(); } return false; } public void start() { - List lvt_1_1_ = getFossilBlocksInArea(); - if (!lvt_1_1_.isEmpty()) { - target = getClosestFossil(lvt_1_1_); - this.entity.getNavigation().moveTo(this.entity.getNavigation().createPath(target, 2), 2); + List blocks = getFossilBlocksInArea(); + if (!blocks.isEmpty()) { + target = getClosestFossil(blocks); + this.entity.getMoveControl().setWantedPosition(target.getX(), target.getY(), target.getZ(), 0.5); } } @@ -50,10 +49,10 @@ private List getFossilBlocksInArea() { return fossilBlocks; } - private BlockPos getClosestFossil(List lvt_1_1_) { - BlockPos closest = lvt_1_1_.get(0).immutable(); + private BlockPos getClosestFossil(List blocks) { + BlockPos closest = blocks.get(0).immutable(); - for (BlockPos pos : lvt_1_1_) { + for (BlockPos pos : blocks) { if(entity.distanceToSqr(pos.getX(), pos.getY(), pos.getZ()) < entity.distanceToSqr(closest.getX(), closest.getY(), closest.getZ())) { closest = pos.immutable(); } @@ -65,7 +64,7 @@ private BlockPos getClosestFossil(List lvt_1_1_) { @Override public boolean canContinueToUse() { if(target != null) { - if(this.entity.distanceToSqr((double)target.getX(), (double)target.getY(), (double)target.getZ()) < 2) { + if(this.entity.distanceToSqr(target.getX(), target.getY(), target.getZ()) < 2) { target = null; entity.setState(1); return false; @@ -79,7 +78,7 @@ public boolean canContinueToUse() { public void tick() { if(target != null) { - this.entity.getNavigation().moveTo(this.entity.getNavigation().createPath(target, 1), 1); + this.entity.getMoveControl().setWantedPosition(target.getX(), target.getY(), target.getZ(), 0.5); } } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralOreGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralOreGoal.java index 8850c408..6c7b85c3 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralOreGoal.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralOreGoal.java @@ -12,28 +12,26 @@ public class FindMineralOreGoal extends Goal { - private IWorldReader world; private EntitySpectrobe entity; private BlockPos target; public FindMineralOreGoal(EntitySpectrobe spectrobe) { this.entity = spectrobe; - this.world = spectrobe.level; } public boolean canUse() { if(entity.getStage() == SpectrobeProperties.Stage.CHILD && entity.isSearching()) { - List lvt_1_1_ = getMineralBlocksInArea(); - return !lvt_1_1_.isEmpty(); + List blocks = getMineralBlocksInArea(); + return !blocks.isEmpty(); } return false; } public void start() { - List lvt_1_1_ = getMineralBlocksInArea(); - if (!lvt_1_1_.isEmpty()) { - target = getClosestMineral(lvt_1_1_); - this.entity.getNavigation().moveTo(this.entity.getNavigation().createPath(target, 2), 2); + List blocks = getMineralBlocksInArea(); + if (!blocks.isEmpty()) { + target = getClosestMineral(blocks); + this.entity.getMoveControl().setWantedPosition(target.getX(), target.getY(), target.getZ(), 1.0D); } } @@ -79,7 +77,7 @@ public boolean canContinueToUse() { public void tick() { if(target != null) { - this.entity.getNavigation().moveTo(this.entity.getNavigation().createPath(target, 1), 1); + this.entity.getMoveControl().setWantedPosition(target.getX(), target.getY(), target.getZ(), 1.0D); } } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralsGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralsGoal.java index 5c090cb9..9c6eb36c 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralsGoal.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FindMineralsGoal.java @@ -2,6 +2,7 @@ import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; import com.spectrobes.spectrobesmod.common.items.minerals.MineralItem; +import com.spectrobes.spectrobesmod.common.registry.SpectrobesBlocks; import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties; import net.minecraft.entity.Entity; import net.minecraft.entity.ai.goal.Goal; @@ -9,12 +10,15 @@ import net.minecraft.entity.passive.DolphinEntity; import net.minecraft.inventory.EquipmentSlotType; import net.minecraft.item.ItemStack; +import net.minecraft.tags.FluidTags; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.IWorldReader; import java.util.List; public class FindMineralsGoal extends Goal { - private IWorldReader world; + private final IWorldReader world; private EntitySpectrobe entity; public FindMineralsGoal(EntitySpectrobe spectrobe) { @@ -24,8 +28,8 @@ public FindMineralsGoal(EntitySpectrobe spectrobe) { public boolean canUse() { if(entity.getStage() == SpectrobeProperties.Stage.CHILD && (entity.isSearching() || entity.getOwner() == null)) { - List lvt_1_1_ = entity.level.getEntitiesOfClass(ItemEntity.class, this.entity.getBoundingBox().inflate(8.0D, 8.0D, 8.0D), EntitySpectrobe.MINERAL_SELECTOR); - return !lvt_1_1_.isEmpty(); + List minerals = entity.level.getEntitiesOfClass(ItemEntity.class, this.entity.getBoundingBox().inflate(8.0D, 8.0D, 8.0D), EntitySpectrobe.MINERAL_SELECTOR); + return !minerals.isEmpty(); } return false; } @@ -37,9 +41,17 @@ public boolean canContinueToUse() { } public void start() { - List lvt_1_1_ = this.entity.level.getEntitiesOfClass(ItemEntity.class, this.entity.getBoundingBox().inflate(8.0D, 8.0D, 8.0D), EntitySpectrobe.MINERAL_SELECTOR); - if (!lvt_1_1_.isEmpty()) { - this.entity.getNavigation().moveTo(lvt_1_1_.get(0), 0.8000000476837158D); + BlockPos blockpos = null; + + List minerals = this.entity.level.getEntitiesOfClass(ItemEntity.class, this.entity.getBoundingBox().inflate(2.0D, 2.0D, 2.0D), EntitySpectrobe.MINERAL_SELECTOR); + + for (ItemEntity mineral : + minerals) { + blockpos = mineral.blockPosition(); + } + + if (blockpos != null) { + this.entity.getMoveControl().setWantedPosition(blockpos.getX(), blockpos.getY(), blockpos.getZ(), 1.0D); } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FollowMasterGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FollowMasterGoal.java index ccaaea6a..22b77159 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FollowMasterGoal.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/FollowMasterGoal.java @@ -5,154 +5,158 @@ package com.spectrobes.spectrobesmod.common.entities.goals; -import java.util.EnumSet; - -import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntityAquaticSpectrobe; import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; import net.minecraft.block.BlockState; import net.minecraft.block.LeavesBlock; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.goal.FollowOwnerGoal; import net.minecraft.entity.ai.goal.Goal; -import net.minecraft.entity.ai.goal.Goal.Flag; import net.minecraft.entity.passive.TameableEntity; -import net.minecraft.pathfinding.FlyingPathNavigator; -import net.minecraft.pathfinding.GroundPathNavigator; -import net.minecraft.pathfinding.PathNavigator; -import net.minecraft.pathfinding.PathNodeType; -import net.minecraft.pathfinding.WalkNodeProcessor; +import net.minecraft.pathfinding.*; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorldReader; +import java.util.EnumSet; + public class FollowMasterGoal extends Goal { - private final EntitySpectrobe tameable; + private final TameableEntity tamable; private LivingEntity owner; - private final IWorldReader world; - private final double followSpeed; - private final PathNavigator navigator; + private final IWorldReader level; + private final double speedModifier; + private final PathNavigator navigation; private int timeToRecalcPath; - private final float maxDist; - private final float minDist; + private final float stopDistance; + private final float startDistance; private float oldWaterCost; - private final boolean teleportToLeaves; - - public FollowMasterGoal(EntitySpectrobe p_i225711_1_, double p_i225711_2_, float p_i225711_4_, float p_i225711_5_, boolean p_i225711_6_) { - this.tameable = p_i225711_1_; - this.world = p_i225711_1_.level; - this.followSpeed = p_i225711_2_; - this.navigator = p_i225711_1_.getNavigation(); - this.minDist = p_i225711_4_; - this.maxDist = p_i225711_5_; - this.teleportToLeaves = p_i225711_6_; - this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); + private final boolean canFly; + + public FollowMasterGoal(TameableEntity entity, double followSpeed, float minDist, float maxDist, boolean canFly) { + this.tamable = entity; + this.level = entity.level; + this.speedModifier = followSpeed; + this.navigation = entity.getNavigation(); + this.startDistance = minDist; + this.stopDistance = maxDist; + this.canFly = canFly; + this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.LOOK)); + if (!(entity.getNavigation() instanceof GroundPathNavigator) + && !(entity.getNavigation() instanceof FlyingPathNavigator) + && !(entity.getNavigation() instanceof SwimmerPathNavigator)) { + throw new IllegalArgumentException("Unsupported navigation type for FollowMasterGoal"); + } } - public boolean canUse() { - LivingEntity lvt_1_1_ = this.tameable.getOwner(); - if (lvt_1_1_ == null) { - return false; - } else if (lvt_1_1_.isSpectator()) { + LivingEntity livingentity = this.tamable.getOwner(); + if (livingentity == null) { return false; - } else if (this.tameable.isOrderedToSit()) { + } else if (livingentity.isSpectator()) { return false; - } else if (this.tameable.IsAttacking()) { + } else if (this.tamable.isOrderedToSit()) { return false; - } else if (this.tameable.isSearching()) { + } else if (this.tamable.getTarget() != null) { return false; - } else if (this.tameable.distanceToSqr(lvt_1_1_) < (double)(this.minDist * this.minDist)) { + } else if (this.tamable.distanceToSqr(livingentity) < (double)(this.startDistance * this.startDistance)) { return false; } else { - this.owner = lvt_1_1_; - return true; + this.owner = livingentity; + return ((EntitySpectrobe)this.tamable).getState() == 0 && !((EntitySpectrobe) this.tamable).isAttacking(); } } + /** + * Returns whether an in-progress EntityAIBase should continue executing + */ public boolean canContinueToUse() { - if (this.navigator.isDone()) { + if (this.navigation.isDone()) { return false; - } else if (this.tameable.isOrderedToSit()) { + } else if (this.tamable.isOrderedToSit()) { return false; - } else if (this.tameable.IsAttacking()) { - return false; - } else if (this.tameable.isSearching()) { + } else if (this.tamable.getTarget() != null) { return false; } else { - return this.tameable.distanceToSqr(this.owner) > (double)(this.maxDist * this.maxDist); + return !(this.tamable.distanceToSqr(this.owner) <= (double)(this.stopDistance * this.stopDistance)); } } + /** + * Execute a one shot task or start executing a continuous task + */ public void start() { this.timeToRecalcPath = 0; - this.oldWaterCost = this.tameable.getPathfindingMalus(PathNodeType.WATER); - this.tameable.setPathfindingMalus(PathNodeType.WATER, 0.0F); + this.oldWaterCost = this.tamable.getPathfindingMalus(PathNodeType.WATER); + this.tamable.setPathfindingMalus(PathNodeType.WATER, 0.0F); } + /** + * Reset the task's internal state. Called when this task is interrupted by another one + */ public void stop() { this.owner = null; - this.navigator.stop(); - this.tameable.setPathfindingMalus(PathNodeType.WATER, this.oldWaterCost); + this.navigation.stop(); + this.tamable.setPathfindingMalus(PathNodeType.WATER, 0.0f); } + /** + * Keep ticking a continuous task that has already been started + */ public void tick() { - this.tameable.getLookControl().setLookAt(this.owner, 10.0F, (float)this.tameable.getMaxHeadXRot()); + this.tamable.getLookControl().setLookAt(this.owner, 10.0F, (float)this.tamable.getMaxHeadXRot()); if (--this.timeToRecalcPath <= 0) { this.timeToRecalcPath = 10; - if (!this.tameable.isLeashed() && !this.tameable.isPassenger()) { - if (this.tameable.distanceToSqr(this.owner) >= 144.0D) { - this.tryToTeleportNearEntity(); + if (!this.tamable.isLeashed() && !this.tamable.isPassenger()) { + if (this.tamable.distanceToSqr(this.owner) >= 144.0D) { + this.teleportToOwner(); } else { - this.navigator.moveTo(this.owner, this.followSpeed); + this.navigation.moveTo(this.owner, this.speedModifier); } } } } - private void tryToTeleportNearEntity() { - BlockPos lvt_1_1_ = this.owner.blockPosition().immutable(); + private void teleportToOwner() { + BlockPos blockpos = this.owner.blockPosition(); - for(int lvt_2_1_ = 0; lvt_2_1_ < 10; ++lvt_2_1_) { - int lvt_3_1_ = this.getRandomNumber(-3, 3); - int lvt_4_1_ = this.getRandomNumber(-1, 1); - int lvt_5_1_ = this.getRandomNumber(-3, 3); - boolean lvt_6_1_ = this.tryToTeleportToLocation(lvt_1_1_.getX() + lvt_3_1_, lvt_1_1_.getY() + lvt_4_1_, lvt_1_1_.getZ() + lvt_5_1_); - if (lvt_6_1_) { + for(int i = 0; i < 10; ++i) { + int j = this.randomIntInclusive(-3, 3); + int k = this.randomIntInclusive(-1, 1); + int l = this.randomIntInclusive(-3, 3); + boolean flag = this.maybeTeleportTo(blockpos.getX() + j, blockpos.getY() + k, blockpos.getZ() + l); + if (flag) { return; } } } - private boolean tryToTeleportToLocation(int p_226328_1_, int p_226328_2_, int p_226328_3_) { - if (Math.abs((double)p_226328_1_ - this.owner.getX()) < 2.0D && Math.abs((double)p_226328_3_ - this.owner.getZ()) < 2.0D) { + private boolean maybeTeleportTo(int pX, int pY, int pZ) { + if (Math.abs((double)pX - this.owner.getX()) < 2.0D && Math.abs((double)pZ - this.owner.getZ()) < 2.0D) { return false; - } else if (!this.isTeleportFriendlyBlock(new BlockPos(p_226328_1_, p_226328_2_, p_226328_3_))) { + } else if (!this.canTeleportTo(new BlockPos(pX, pY, pZ))) { return false; } else { - this.tameable.moveTo((double)((float)p_226328_1_ + 0.5F), (double)p_226328_2_, (double)((float)p_226328_3_ + 0.5F), this.tameable.yRot, this.tameable.xRot); - this.navigator.stop(); + this.tamable.moveTo((double)pX + 0.5D, (double)pY, (double)pZ + 0.5D, this.tamable.yRot, this.tamable.xRot); + this.navigation.stop(); return true; } } - private boolean isTeleportFriendlyBlock(BlockPos p_226329_1_) { - PathNodeType lvt_2_1_ = new WalkNodeProcessor().getBlockPathType(this.world, p_226329_1_.getX(), p_226329_1_.getY(), p_226329_1_.getZ()); - if (lvt_2_1_ != PathNodeType.WALKABLE) { - if(tameable instanceof EntityAquaticSpectrobe && (lvt_2_1_ == PathNodeType.WATER || lvt_2_1_ == PathNodeType.WATER_BORDER)) { - return true; - } + private boolean canTeleportTo(BlockPos pPos) { + PathNodeType pathnodetype = WalkNodeProcessor.getBlockPathTypeStatic(this.level, pPos.mutable()); + if (pathnodetype != PathNodeType.WALKABLE && pathnodetype != PathNodeType.WATER) { return false; } else { - BlockState lvt_3_1_ = this.world.getBlockState(p_226329_1_.below()); - if (!this.teleportToLeaves && lvt_3_1_.getBlock() instanceof LeavesBlock) { + BlockState blockstate = this.level.getBlockState(pPos.below()); + if (!this.canFly && blockstate.getBlock() instanceof LeavesBlock) { return false; } else { - BlockPos lvt_4_1_ = p_226329_1_.subtract(this.tameable.blockPosition().immutable()); - return this.world.noCollision(this.tameable, this.tameable.getBoundingBox().move(lvt_4_1_)); + BlockPos blockpos = pPos.subtract(this.tamable.blockPosition()); + return this.level.noCollision(this.tamable, this.tamable.getBoundingBox().move(blockpos)); } } } - private int getRandomNumber(int p_226327_1_, int p_226327_2_) { - return this.tameable.getRandom().nextInt(p_226327_2_ - p_226327_1_ + 1) + p_226327_1_; + private int randomIntInclusive(int pMin, int pMax) { + return this.tamable.getRandom().nextInt(pMax - pMin + 1) + pMin; } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/SpectrobeFindWaterGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/SpectrobeFindWaterGoal.java new file mode 100644 index 00000000..16344466 --- /dev/null +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/SpectrobeFindWaterGoal.java @@ -0,0 +1,24 @@ +package com.spectrobes.spectrobesmod.common.entities.goals; + +import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; +import net.minecraft.entity.CreatureEntity; +import net.minecraft.entity.ai.goal.FindWaterGoal; + +public class SpectrobeFindWaterGoal extends FindWaterGoal { + private final CreatureEntity spectrobe; + + public SpectrobeFindWaterGoal(CreatureEntity p_i48936_1_) { + super(p_i48936_1_); + this.spectrobe = p_i48936_1_; + } + + @Override + public boolean canUse() { + EntitySpectrobe spectrobeEntity = ((EntitySpectrobe)this.spectrobe); + if(spectrobeEntity.getOwner() != null && + spectrobeEntity.getState() == 0){ + return false; + } + return super.canUse(); + } +} diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/TargetKrawlGoal.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/TargetKrawlGoal.java new file mode 100644 index 00000000..3d831860 --- /dev/null +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/goals/TargetKrawlGoal.java @@ -0,0 +1,25 @@ +package com.spectrobes.spectrobesmod.common.entities.goals; +import com.spectrobes.spectrobesmod.SpectrobesInfo; +import com.spectrobes.spectrobesmod.common.entities.spectrobes.EntitySpectrobe; +import com.spectrobes.spectrobesmod.common.spectrobes.SpectrobeProperties; +import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal; +import net.minecraft.entity.passive.TameableEntity; + +import javax.annotation.Nullable; +import java.util.function.Predicate; + +public class TargetKrawlGoal extends NearestAttackableTargetGoal { + public TargetKrawlGoal(TameableEntity entity, Class targetClass, boolean mustSee, @Nullable Predicate predicate) { + super(entity, targetClass, 0, mustSee, false, predicate); + } + + @Override + public boolean canUse() { + return super.canUse() && !(((EntitySpectrobe)mob).getStage() == SpectrobeProperties.Stage.CHILD); + } + + @Override + public boolean canContinueToUse() { + return this.targetConditions.test(this.mob, this.target); + } +} diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/krawl/EntityKrawl.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/krawl/EntityKrawl.java index d29ea543..80ff115e 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/krawl/EntityKrawl.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/krawl/EntityKrawl.java @@ -111,6 +111,7 @@ public void aiStep() { protected void registerGoals() { // this.goalSelector.addGoal(5, new BreedGoal(this,10)); todo: Make krawl eat mass and duplicate? + this.goalSelector.addGoal(0, new SwimGoal(this)); this.goalSelector.addGoal(1, new AttackSpectrobeGoal(this, true, true)); this.goalSelector.addGoal(2, new RestrictSunGoal(this)); this.goalSelector.addGoal(3, new FleeSunGoal(this, 1.0D)); diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAquaticSpectrobe.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAquaticSpectrobe.java index f4115948..81908bc2 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAquaticSpectrobe.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAquaticSpectrobe.java @@ -1,5 +1,6 @@ package com.spectrobes.spectrobesmod.common.entities.spectrobes; +import com.spectrobes.spectrobesmod.common.entities.goals.AquaticJumpGoal; import net.minecraft.block.Blocks; import net.minecraft.entity.*; import net.minecraft.entity.ai.attributes.Attributes; @@ -11,7 +12,9 @@ import net.minecraft.pathfinding.*; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; +import net.minecraft.tags.BlockTags; import net.minecraft.tags.FluidTags; +import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; @@ -28,8 +31,8 @@ public abstract class EntityAquaticSpectrobe extends EntitySpectrobe { private static final EntityPredicate SWIM_WITH_PLAYER_TARGETING = (new EntityPredicate()).range(10.0D).allowSameTeam().allowInvulnerable().allowUnseeable(); public EntityAquaticSpectrobe(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); - this.setPathfindingMalus(PathNodeType.WATER, 1.0F); - this.setPathfindingMalus(PathNodeType.WALKABLE, 1.0F); + this.setPathfindingMalus(PathNodeType.WATER, 0.0F); + this.setPathfindingMalus(PathNodeType.WALKABLE, 0.0F); this.moveControl = new MoveHelperController(this); this.lookControl = new SpectrobeLookController(this, 10); } @@ -58,10 +61,10 @@ protected PathNavigator createNavigation(World world) { protected void registerGoals() { super.registerGoals(); // this.goalSelector.addGoal(0, new SwimWithPlayerGoal(this, 1.0D)); - this.goalSelector.addGoal(3, new RandomSwimmingGoal(this, .5D, 5)); - this.goalSelector.addGoal(1, new FindWaterGoal(this)); - this.goalSelector.addGoal(2, new LookRandomlyGoal(this)); + this.goalSelector.addGoal(8, new RandomSwimmingGoal(this, 1D, 10)); + this.goalSelector.addGoal(4, new FindWaterGoal(this)); this.goalSelector.addGoal(8, new FollowBoatGoal(this)); + this.goalSelector.addGoal(5, new AquaticJumpGoal(this, 10)); } @Override @@ -112,99 +115,6 @@ public void mate() { protected abstract int getMaxLitterSize(); - static class SwimWithPlayerGoal extends Goal { - private final EntityAquaticSpectrobe spectrobe; - private final double speed; - private PlayerEntity targetPlayer; - - SwimWithPlayerGoal(EntityAquaticSpectrobe spectrobeIn, double speedIn) { - this.spectrobe = spectrobeIn; - this.speed = speedIn; - this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); - } - - public boolean canUse() { - this.targetPlayer = this.spectrobe.level.getNearestPlayer(EntityAquaticSpectrobe.SWIM_WITH_PLAYER_TARGETING, this.spectrobe); - return this.targetPlayer == null ? false : this.targetPlayer.isSwimming(); - } - - public boolean canContinueToUse() { - return this.targetPlayer != null && this.targetPlayer.isSwimming() && this.spectrobe.distanceToSqr(this.targetPlayer) < 256.0D; - } - - public void start() { - this.targetPlayer.addEffect(new EffectInstance(Effects.DOLPHINS_GRACE, 100)); - } - - public void stop() { - this.targetPlayer = null; - this.spectrobe.getNavigation().stop(); - } - - - public void tick() { - this.spectrobe.getLookControl().setLookAt(this.targetPlayer, (float)(this.spectrobe.getMaxHeadYRot() + 20), (float)this.spectrobe.getMaxHeadXRot()); - if (this.spectrobe.distanceToSqr(this.targetPlayer) < 6.25D) { - this.spectrobe.getNavigation().stop(); - } else { - this.spectrobe.getNavigation().moveTo(this.targetPlayer, this.speed); - } - - if (this.targetPlayer.isSwimming() && this.targetPlayer.level.random.nextInt(6) == 0) { - this.targetPlayer.addEffect(new EffectInstance(Effects.DOLPHINS_GRACE, 100)); - } - - } - } - static class MoveHelperController_ONE extends MovementController { - private final EntityAquaticSpectrobe dolphin; - - public MoveHelperController_ONE(EntityAquaticSpectrobe dolphinIn) { - super(dolphinIn); - this.dolphin = dolphinIn; - } - - public void tick() { - if (this.dolphin.isInWater()) { - this.dolphin.setDeltaMovement(this.dolphin.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); - } - - if (this.operation == Action.MOVE_TO && !this.dolphin.getNavigation().isDone()) { - double d0 = this.wantedX - this.dolphin.getX(); - double d1 = this.wantedY - this.dolphin.getY(); - double d2 = this.wantedZ - this.dolphin.getZ(); - double d3 = d0 * d0 + d1 * d1 + d2 * d2; - if (d3 < 2.500000277905201E-7D) { - this.mob.setZza(0.0F); - } else { - float f = (float)(MathHelper.atan2(d2, d0) * 57.2957763671875D) - 90.0F; - this.dolphin.yRot = this.rotlerp(this.dolphin.yRot, f, 10.0F); - this.dolphin.yBodyRot = this.dolphin.yRot; - this.dolphin.yHeadRot = this.dolphin.yRot; - float f1 = (float)(this.speedModifier * this.dolphin.getAttributeValue(Attributes.MOVEMENT_SPEED)); - if (this.dolphin.isInWater()) { - this.dolphin.setSpeed(f1 * 0.02F); - float f2 = -((float)(MathHelper.atan2(d1, (double)MathHelper.sqrt(d0 * d0 + d2 * d2)) * 57.2957763671875D)); - f2 = MathHelper.clamp(MathHelper.wrapDegrees(f2), -85.0F, 85.0F); - this.dolphin.xRot = this.rotlerp(this.dolphin.xRot, f2, 5.0F); - float f3 = MathHelper.cos(this.dolphin.xRot * 0.017453292F); - float f4 = MathHelper.sin(this.dolphin.xRot * 0.017453292F); - this.dolphin.zza = f3 * f1; - this.dolphin.yya = -f4 * f1; - } else { - this.dolphin.setSpeed(f1 * 0.1F); - } - } - } else { - this.dolphin.setSpeed(0.0F); - this.dolphin.setXxa(0.0F); - this.dolphin.setYya(0.0F); - this.dolphin.setZza(0.0F); - } - - } - } - static class Navigator extends SwimmerPathNavigator { Navigator(EntityAquaticSpectrobe p_i48815_1_, World p_i48815_2_) { super(p_i48815_1_, p_i48815_2_); @@ -214,62 +124,108 @@ protected boolean canUpdatePath() { return true; } - protected PathFinder createPathFinder(int p_179679_1_) { + protected PathFinder createPathFinder(int nodes) { this.nodeEvaluator = new WalkAndSwimNodeProcessor(); - return new PathFinder(this.nodeEvaluator, p_179679_1_); + return new PathFinder(this.nodeEvaluator, nodes); } public boolean isStableDestination(BlockPos p_188555_1_) { - if (this.mob instanceof EntityAquaticSpectrobe) { - - return this.level.getBlockState(p_188555_1_).getBlock() == Blocks.WATER - || !this.level.getBlockState(p_188555_1_.below()).isAir(); - } - - return !this.level.getBlockState(p_188555_1_.below()).isAir(); + return super.isStableDestination(p_188555_1_) || !this.level.getBlockState(p_188555_1_.below()).isAir(); +// +// if (this.mob instanceof EntityAquaticSpectrobe) { +// } +// +// return !this.level.getBlockState(p_188555_1_.below()).isAir(); } } static class MoveHelperController extends MovementController { - private final EntityAquaticSpectrobe dolphin; + private final EntityAquaticSpectrobe spectrobe; public MoveHelperController(EntityAquaticSpectrobe dolphinIn) { super(dolphinIn); - this.dolphin = dolphinIn; + this.spectrobe = dolphinIn; } + public void tick() { - if (this.dolphin.isInWater()) { - this.dolphin.setDeltaMovement(this.dolphin.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); + if (this.spectrobe.isInWater()) { + this.spectrobe.setDeltaMovement(this.spectrobe.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); } -// if (this.action == Action.MOVE_TO && !this.dolphin.getNavigator().noPath()) { - double d0 = this.wantedX - this.dolphin.getX(); - double d1 = this.wantedY - this.dolphin.getY(); - double d2 = this.wantedZ - this.dolphin.getZ(); + if (this.operation == MovementController.Action.MOVE_TO && !this.spectrobe.getNavigation().isDone()) { + double d0 = this.wantedX - this.spectrobe.getX(); + double d1 = this.wantedY - this.spectrobe.getY(); + double d2 = this.wantedZ - this.spectrobe.getZ(); double d3 = d0 * d0 + d1 * d1 + d2 * d2; - if (d3 < 2.500000277905201E-7D) { + if (d3 < (double)2.5000003E-7F) { this.mob.setZza(0.0F); } else { - float f = (float)(MathHelper.atan2(d2, d0) * 57.2957763671875D) - 90.0F; - this.dolphin.yRot = this.rotlerp(this.dolphin.yRot, f, 10.0F); - this.dolphin.yBodyRot = this.dolphin.yRot; - this.dolphin.yHeadRot = this.dolphin.yRot; - float f1 = (float)(this.speedModifier * this.dolphin.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); - if (this.dolphin.isInWater()) { - this.dolphin.setSpeed(f1 * 0.5F); - float f2 = -((float)(MathHelper.atan2(d1, (double)MathHelper.sqrt(d0 * d0 + d2 * d2)) * 57.2957763671875D)); + float f = (float)(MathHelper.atan2(d2, d0) * (double)(180F / (float)Math.PI)) - 90.0F; + this.spectrobe.yRot = this.rotlerp(this.spectrobe.yRot, f, 10.0F); + this.spectrobe.yBodyRot = this.spectrobe.yRot; + this.spectrobe.yHeadRot = this.spectrobe.yRot; + float f1 = (float)(this.speedModifier * this.spectrobe.getAttributeValue(Attributes.MOVEMENT_SPEED)); + if (this.spectrobe.isInWater()) { + this.spectrobe.setSpeed(f1 * 0.2F); + float f2 = -((float)(MathHelper.atan2(d1, (double)MathHelper.sqrt(d0 * d0 + d2 * d2)) * (double)(180F / (float)Math.PI))); f2 = MathHelper.clamp(MathHelper.wrapDegrees(f2), -85.0F, 85.0F); - this.dolphin.xRot = this.rotlerp(this.dolphin.xRot, f2, 5.0F); - float f3 = MathHelper.cos(this.dolphin.xRot * 0.017453292F); - float f4 = MathHelper.sin(this.dolphin.xRot * 0.017453292F); - this.dolphin.zza = f3 * f1; - this.dolphin.yya = -f4 * f1; + this.spectrobe.xRot = this.rotlerp(this.spectrobe.xRot, f2, 5.0F); + float f3 = MathHelper.cos(this.spectrobe.xRot * ((float)Math.PI / 180F)); + float f4 = MathHelper.sin(this.spectrobe.xRot * ((float)Math.PI / 180F)); + this.spectrobe.zza = f3 * f1; + this.spectrobe.yya = -f4 * f1; } else { - this.dolphin.setSpeed(f1); + if (d1 > (double)this.mob.maxUpStep) { + this.mob.getJumpControl().jump(); + this.operation = MovementController.Action.JUMPING; + } + this.spectrobe.setSpeed(f1 * 0.3f); } + + } + } else if (this.operation == MovementController.Action.JUMPING) { + this.mob.setSpeed((float)(this.speedModifier * this.mob.getAttributeValue(Attributes.MOVEMENT_SPEED))); + if (this.mob.isOnGround()) { + this.operation = MovementController.Action.WAIT; } + } else { + this.spectrobe.setSpeed(0.0F); + } } + +// public void tick() { +// if (this.spectrobe.isInWater()) { +// this.spectrobe.setDeltaMovement(this.spectrobe.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); +// } +// +//// if (this.action == Action.MOVE_TO && !this.dolphin.getNavigator().noPath()) { +// double d0 = this.wantedX - this.spectrobe.getX(); +// double d1 = this.wantedY - this.spectrobe.getY(); +// double d2 = this.wantedZ - this.spectrobe.getZ(); +// double d3 = d0 * d0 + d1 * d1 + d2 * d2; +// if (d3 < 2.500000277905201E-7D) { +// this.mob.setZza(0.0F); +// } else { +// float f = (float)(MathHelper.atan2(d2, d0) * 57.2957763671875D) - 90.0F; +// this.spectrobe.yRot = this.rotlerp(this.spectrobe.yRot, f, 10.0F); +// this.spectrobe.yBodyRot = this.spectrobe.yRot; +// this.spectrobe.yHeadRot = this.spectrobe.yRot; +// float f1 = (float)(this.speedModifier * this.spectrobe.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); +// if (this.spectrobe.isInWater()) { +// this.spectrobe.setSpeed(f1 * 0.5F); +// float f2 = -((float)(MathHelper.atan2(d1, (double)MathHelper.sqrt(d0 * d0 + d2 * d2)) * 57.2957763671875D)); +// f2 = MathHelper.clamp(MathHelper.wrapDegrees(f2), -85.0F, 85.0F); +// this.spectrobe.xRot = this.rotlerp(this.spectrobe.xRot, f2, 5.0F); +// float f3 = MathHelper.cos(this.spectrobe.xRot * 0.017453292F); +// float f4 = MathHelper.sin(this.spectrobe.xRot * 0.017453292F); +// this.spectrobe.zza = f3 * f1; +// this.spectrobe.yya = -f4 * f1; +// } else { +// this.spectrobe.setSpeed(f1); +// } +// } +// } } public class SpectrobeLookController extends LookController { @@ -302,7 +258,6 @@ public void tick() { } else if (f > (float)this.maxYRotFromCenter) { this.mob.yBodyRot += 4.0F; } - } } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAvianSpectrobe.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAvianSpectrobe.java index 17140481..f2042ea7 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAvianSpectrobe.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityAvianSpectrobe.java @@ -5,6 +5,7 @@ import net.minecraft.entity.ai.goal.WaterAvoidingRandomFlyingGoal; import net.minecraft.entity.ai.goal.WaterAvoidingRandomWalkingGoal; import net.minecraft.entity.passive.IFlyingAnimal; +import net.minecraft.pathfinding.PathNodeType; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.World; @@ -19,6 +20,7 @@ public abstract class EntityAvianSpectrobe extends EntitySpectrobe implements IF public EntityAvianSpectrobe(EntityType entityTypeIn, World worldIn) { super(entityTypeIn, worldIn); this.moveControl = new FlyingMovementController(this, 10, false); + this.setPathfindingMalus(PathNodeType.OPEN, 0.0F); } @Override @@ -56,4 +58,9 @@ private void calculateFlapping() { this.flap += this.flapping * 2.0F; } + + @Override + public boolean canFly() { + return true; + } } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityCrustaceanSpectrobe.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityCrustaceanSpectrobe.java index 1eb63842..91be9ea8 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityCrustaceanSpectrobe.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityCrustaceanSpectrobe.java @@ -53,10 +53,10 @@ public void aiStep() { @Override protected void registerGoals() { super.registerGoals(); - this.goalSelector.addGoal(0, new BreatheAirGoal(this)); this.goalSelector.addGoal(2, new FindWaterGoal(this)); - this.goalSelector.addGoal(4, new LookRandomlyGoal(this)); - this.goalSelector.addGoal(4, new RandomWalkingGoal(this, 1)); + this.goalSelector.addGoal(9, new LookRandomlyGoal(this)); + this.goalSelector.addGoal(7, new RandomWalkingGoal(this, 1)); + this.goalSelector.addGoal(7, new RandomSwimmingGoal(this, 1, 10)); this.goalSelector.addGoal(8, new FollowBoatGoal(this)); } @@ -116,9 +116,13 @@ static class MoveHelperController extends MovementController { this.fish = p_i48857_1_; } - public void tick() { - if (this.fish.isEyeInFluid(FluidTags.WATER)) { + if (this.fish.isInWater()) { + if(this.fish.getTarget() != null && this.fish.getTarget().getY() > this.fish.getY()) { + this.fish.getNavigation().setCanFloat(true); + } else { + this.fish.getNavigation().setCanFloat(false); + } this.fish.setDeltaMovement(this.fish.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); } @@ -137,80 +141,6 @@ public void tick() { } } - static class Navigator extends SwimmerPathNavigator { - Navigator(EntityCrustaceanSpectrobe p_i48815_1_, World p_i48815_2_) { - super(p_i48815_1_, p_i48815_2_); - } - - protected boolean canUpdatePath() { - return true; - } - - protected PathFinder createPathFinder(int p_179679_1_) { - this.nodeEvaluator = new WalkAndSwimNodeProcessor(); - return new PathFinder(this.nodeEvaluator, p_179679_1_); - } - - public boolean isStableDestination(BlockPos p_188555_1_) { - if (this.mob instanceof EntityCrustaceanSpectrobe) { - - return this.level.getBlockState(p_188555_1_).getBlock() == Blocks.WATER - || !this.level.getBlockState(p_188555_1_.below()).isAir(); - } - - return !this.level.getBlockState(p_188555_1_.below()).isAir(); - } - } - - static class MoveHelperController_ONE extends MovementController { - private final EntityCrustaceanSpectrobe dolphin; - - public MoveHelperController_ONE(EntityCrustaceanSpectrobe dolphinIn) { - super(dolphinIn); - this.dolphin = dolphinIn; - } - - public void tick() { - if (this.dolphin.isInWater()) { - this.dolphin.setDeltaMovement(this.dolphin.getDeltaMovement().add(0.0D, 0.005D, 0.0D)); - } - -// if (this.action == Action.MOVE_TO && !this.dolphin.getNavigator().noPath()) { - double d0 = this.wantedX - this.dolphin.getX(); - double d1 = this.wantedY - this.dolphin.getY(); - double d2 = this.wantedZ - this.dolphin.getZ(); - double d3 = d0 * d0 + d1 * d1 + d2 * d2; - if (d3 < 2.500000277905201E-7D) { - this.mob.setZza(0.0F); - } else { - float f = (float)(MathHelper.atan2(d2, d0) * 57.2957763671875D) - 90.0F; - this.dolphin.yRot = this.rotlerp(this.dolphin.yRot, f, 10.0F); - this.dolphin.yBodyRot = this.dolphin.yRot; - this.dolphin.yHeadRot = this.dolphin.yRot; - float f1 = (float)(this.speedModifier * this.dolphin.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); - if (this.dolphin.isInWater()) { - this.dolphin.setSpeed(f1 * 0.2F); - float f2 = -((float)(MathHelper.atan2(d1, (double)MathHelper.sqrt(d0 * d0 + d2 * d2)) * 57.2957763671875D)); - f2 = MathHelper.clamp(MathHelper.wrapDegrees(f2), -85.0F, 85.0F); - this.dolphin.xRot = this.rotlerp(this.dolphin.xRot, f2, 5.0F); - float f3 = MathHelper.cos(this.dolphin.xRot * 0.017453292F); - float f4 = MathHelper.sin(this.dolphin.xRot * 0.017453292F); - this.dolphin.zza = f3 * f1; - this.dolphin.yya = -f4 * f1; - } else { - this.dolphin.setSpeed(f1); - } - } -// } else { -// this.dolphin.setAIMoveSpeed(0.0F); -// this.dolphin.setMoveStrafing(0.0F); -// this.dolphin.setMoveVertical(0.0F); -// this.dolphin.setMoveForward(0.0F); -// } - - } - } - public class SpectrobeLookController extends LookController { private final int maxYRotFromCenter; diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityMammalSpectrobe.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityMammalSpectrobe.java index ef9fb9a5..81c162a5 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityMammalSpectrobe.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntityMammalSpectrobe.java @@ -17,7 +17,7 @@ public EntityMammalSpectrobe(EntityType entityTypeIn, protected void registerGoals() { super.registerGoals(); this.goalSelector.addGoal(2, new RandomWalkingGoal(this, 0.2d)); - this.goalSelector.addGoal(6, new SwimGoal(this)); + this.goalSelector.addGoal(2, new SwimGoal(this)); this.goalSelector.addGoal(6, new WaterAvoidingRandomWalkingGoal(this, 2)); } diff --git a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntitySpectrobe.java b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntitySpectrobe.java index 9df23631..6c9a9e0a 100644 --- a/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntitySpectrobe.java +++ b/src/main/java/com/spectrobes/spectrobesmod/common/entities/spectrobes/EntitySpectrobe.java @@ -21,7 +21,10 @@ import net.minecraft.entity.ai.goal.*; import net.minecraft.entity.item.ItemEntity; import net.minecraft.entity.monster.MonsterEntity; +import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.TameableEntity; +import net.minecraft.entity.passive.WolfEntity; +import net.minecraft.entity.passive.horse.LlamaEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; @@ -55,10 +58,9 @@ public abstract class EntitySpectrobe extends TameableEntity implements IEntityAdditionalSpawnData, IAnimatable, IHasNature { public static final Predicate MINERAL_SELECTOR = (itemEntity) -> !itemEntity.hasPickUpDelay() && itemEntity.isAlive() && itemEntity.getItem().getItem() instanceof MineralItem; - private static final Predicate TARGET_KRAWL = (entity) -> { + private static final Predicate TARGET_KRAWL = (entity) -> { EntityType entitytype = entity.getType(); - return entitytype.getClass().isAssignableFrom(EntityKrawl.class) - && !((EntityKrawl)entity).isVortex(); + return !(entity).isVortex(); }; private boolean recentInteract = false; private int ticksTillInteract = 0; @@ -100,27 +102,29 @@ public EntitySpectrobe(EntityType entityTypeIn, protected void registerGoals() { super.registerGoals(); - this.goalSelector.addGoal(0, new AttackKrawlGoal(this, true, true)); + this.goalSelector.addGoal(3, new FollowMasterGoal(this, 1, 2, 10, canFly())); + this.goalSelector.addGoal(1, new AttackKrawlGoal(this, false, true)); this.goalSelector.addGoal(1, new FindMineralsGoal(this)); this.goalSelector.addGoal(1, new FindFossilsGoal(this)); this.goalSelector.addGoal(1, new FindMineralOreGoal(this)); - this.goalSelector.addGoal(2, new FollowMasterGoal(this,0.3f , 1, 15, true)); - this.goalSelector.addGoal(5, new LookAtGoal(this, PlayerEntity.class, 6.0F)); - this.goalSelector.addGoal(3, new MeleeAttackGoal(this,1f , true)); + this.goalSelector.addGoal(3, new AvoidKrawlGoal(this, EntityKrawl.class, 24.0F, 1.5D, 1.5D)); + this.goalSelector.addGoal(4, new LeapAtTargetGoal(this, 0.4f)); + this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.2f, true)); + this.goalSelector.addGoal(8, new LookAtGoal(this, PlayerEntity.class, 8.0F)); + this.goalSelector.addGoal(8, new LookRandomlyGoal(this)); + this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this)); this.targetSelector.addGoal(1, new OwnerHurtTargetGoal(this)); - this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, EntityKrawl.class, 10, true, false, (entity) -> true)); - this.targetSelector.addGoal(2, new NearestAttackableTargetGoal(this, EntityKrawl.class, true)); - this.targetSelector.addGoal(3, (new HurtByTargetGoal(this, new Class[0])).setAlertOthers(new Class[0])); - this.targetSelector.addGoal(5, new NonTamedTargetGoal(this, EntityKrawl.class, false, TARGET_KRAWL)); + this.targetSelector.addGoal(2, (new HurtByTargetGoal(this))); + this.targetSelector.addGoal(3, new TargetKrawlGoal(this, EntityKrawl.class, false, TARGET_KRAWL)); } public static AttributeModifierMap.MutableAttribute setCustomAttributes() { return MonsterEntity.createMobAttributes() - .add(Attributes.MOVEMENT_SPEED, (double)0.5F) + .add(Attributes.MOVEMENT_SPEED, (double)1.0D) .add(Attributes.MAX_HEALTH, 20.0D) .add(Attributes.ATTACK_DAMAGE, 5.0D) - .add(Attributes.ATTACK_SPEED, 0.25f) + .add(Attributes.ATTACK_SPEED, 1f) .add(Attributes.FOLLOW_RANGE, 10.0D) .add(Attributes.ATTACK_KNOCKBACK, 5.0D); } @@ -131,6 +135,11 @@ public boolean isOrderedToSit() { } public void setState(int state) { entityData.set(STATE, state); } + public int getState() { return entityData.get(STATE); } + + public boolean canFly() { + return false; + } @Override //processInteract