Skip to content

Commit

Permalink
Fix a bug where foxie stays in sleeping pose even tho a player looks …
Browse files Browse the repository at this point in the history
…at her + Fix a bug where foxie's pathfinding allows water as path
  • Loading branch information
mysticalfoxie committed Sep 29, 2023
1 parent 49fc416 commit cd3cf60
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {

apply plugin: 'net.minecraftforge.gradle'

version = '0.2.0'
version = '0.2.1'
group = 'me.m1chelle99.foxiemc'
archivesBaseName = 'foxiemc'
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/m1chelle99/foxiemc/entity/foxie/Foxie.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public Foxie(EntityType<? extends TamableAnimal> type, Level level) {
this.ownerControl = new FoxieOwnerControl(this);
this.huntControl = new FoxieHuntControl();

this.setPathfindingMalus(BlockPathTypes.DANGER_OTHER, 0.0F);
this.setPathfindingMalus(BlockPathTypes.DAMAGE_OTHER, 0.0F);
this.setPathfindingMalus(BlockPathTypes.DANGER_OTHER, 16.0F);
this.setPathfindingMalus(BlockPathTypes.DAMAGE_OTHER, 16.0F);
this.setPathfindingMalus(BlockPathTypes.LEAVES, 0.0F);
this.setPathfindingMalus(BlockPathTypes.WATER, 0.0F);
this.setPathfindingMalus(BlockPathTypes.WATER, -1.0F);

this.setCanPickUpLoot(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public boolean canUse() {
@Override
public boolean canContinueToUse() {
if (!super.canContinueToUse()) return false;
if (this.areThreadsNearby()) return false;
return this.canSleepAtTimeOfDay();
}

Expand All @@ -42,11 +43,8 @@ public void stop() {
if (!this._foxie.getNavigation().isDone())
this._foxie.getNavigation().stop();

if (this._foxie.aiControl.hasActivity(FoxieActivities.Sleep))
this._foxie.aiControl.startActivity(FoxieActivities.None);

var stillOnSearch = FoxieActivities.SeekSleepShelter;
if (this._foxie.aiControl.hasActivity(stillOnSearch))
if (this._foxie.aiControl.hasActivity(FoxieActivities.Sleep) ||
this._foxie.aiControl.hasActivity(FoxieActivities.SeekSleepShelter))
this._foxie.aiControl.startActivity(FoxieActivities.None);
}

Expand All @@ -62,9 +60,9 @@ private boolean areThreadsNearby() {
var boundary = this._foxie.getBoundingBox().inflate(10, 6, 10);
var level = this._foxie.level;
var threads = level.getEntities(this._foxie, boundary, entity -> {
if (entity.isSprinting()) return true;
if (entity instanceof Monster) return true;
if (!(entity instanceof Player player)) return false;
if (player.isSpectator()) return false;
return !player.isCrouching();
});

Expand Down Expand Up @@ -97,6 +95,14 @@ public void tick() {
this._cooldown = this._foxie.getRandom().nextInt(20, 100);
return;
}

if (this._foxie.isSleeping()) {
this._foxie.stopSleeping();

var activity = FoxieActivities.SeekSleepShelter;
if (!this._foxie.aiControl.hasActivity(activity))
this._foxie.aiControl.startActivity(activity);
}

this.setNewTargetPosition();
this._cooldown = this._foxie.getRandom().nextInt(20, 100);
Expand All @@ -110,7 +116,7 @@ private boolean isDesiredPosition(BlockPos pos) {
if (this._foxie.level.canSeeSky(pos)) return false;
var engine = this._foxie.level.getLightEngine();
var light = engine.getRawBrightness(pos, 0);
if (light > 12) return false;
if (light > 13) return false;
if (light <= 8) return false;
return !this.areThreadsNearby();
}
Expand All @@ -123,11 +129,12 @@ private void setNewTargetPosition() {
if (_target != null)
return;

var target = Pathfinder
this._target = Pathfinder
.getPathInLookDirection(this._foxie, 20, 4, 10);
if (target == null)
if (_target == null)
return;

this._target = new BlockPos(target);
this._target = Pathfinder
.getRandomPositionWithin(this._foxie, 15, 4, 6);
}
}

0 comments on commit cd3cf60

Please sign in to comment.