Skip to content

Commit

Permalink
Fix some AI Goal Interference + Add spawning and replace vanilla Fox
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticalfoxie committed Sep 28, 2023
1 parent 6020c70 commit c8b1095
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,6 @@ public void setupAnim(
this.setRotateAngle(
this.rHindLeg02, 0.8996066167365371F, 0.0F, 0.0F);
this.setRotateAngleDeg(this.rHindpaw, 90, 0, 0);
this.head.xRot -= Math.toRadians(20);
}


Expand Down
6 changes: 5 additions & 1 deletion src/main/java/me/m1chelle99/foxiemc/entity/foxie/Foxie.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.control.MoveControl;
import net.minecraft.world.entity.ai.util.DefaultRandomPos;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -39,7 +40,7 @@ public class Foxie extends TamableAnimal {
public Foxie(EntityType<? extends TamableAnimal> type, Level level) {
super(type, level);

this.moveControl = new FoxieMoveControl(this);
this.moveControl = new MoveControl(this);
this.lookControl = new FoxieLookControl(this);
this.dataControl = new FoxieDataControl(this);
this.aiControl = new FoxieAIControl(this);
Expand Down Expand Up @@ -207,6 +208,9 @@ protected void onOffspringSpawnedFromEgg(Player player, @NotNull Mob mob) {
if (this.level.isClientSide)
return InteractionResult.PASS;

if (hand.name().equals("OFF_HAND"))
return InteractionResult.PASS;

if (this.ownerControl.canInteract(player))
return this.ownerControl.interact(player);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public void trust(@Nullable UUID id) {
}

public boolean isCommanded() {
if (!this._foxie.aiControl.hasActivity(FoxieActivities.Obey))
return false;
return !this.hasCommand(FoxieCommands.None);
}

Expand Down Expand Up @@ -172,8 +174,9 @@ public void setCommand(FoxieCommands command) {
}

public boolean canBeCommanded() {
if (this._foxie.isInWater()) return false;
var activity = this._foxie.dataControl.getActivity();
if (activity == FoxieActivities.AvoidFluid) return false;
if (activity == FoxieActivities.SeekRainShelter) return false;
return activity != FoxieActivities.Panic;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ private InteractionResult ownerInteract(Player player) {
}

if (!this._foxie.aiControl.canBeCommanded())
return InteractionResult.SUCCESS;
return InteractionResult.PASS;

if (!this._foxie.aiControl.isCommanded())
this._foxie.aiControl.setCommand(FoxieCommands.Sit);
else
this._foxie.aiControl.setCommand(FoxieCommands.None);

return InteractionResult.PASS;
return InteractionResult.SUCCESS;
}

public InteractionResult interact(Player player) {
if (this._cooldown > 0) return InteractionResult.SUCCESS;
this._cooldown = 1;
if (this._cooldown > 0) return InteractionResult.PASS;
this._cooldown = 10;

if (this.isTame() && this.isOwner(player.getUUID()))
return this.ownerInteract(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public void start() {
var mod = FoxieMovementSpeed.AVOID_PLAYER;
this._foxie.runTo(position, mod);
}

public void stop() {
this._foxie.getNavigation().stop();
}

@Override
public void tick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void start() {

@Override
public void stop() {
this._foxie.aiControl.startActivity(FoxieActivities.None);
this._foxie.getNavigation().stop();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public void start() {

@Override
public void stop() {
this._foxie.aiControl.startActivity(FoxieActivities.None);
if (this._foxie.aiControl.hasActivity(FoxieActivities.AvoidFluid) ||
this._foxie.aiControl.hasActivity(FoxieActivities.AvoidLava))
this._foxie.aiControl.startActivity(FoxieActivities.None);
this._foxie.getNavigation().stop();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.m1chelle99.foxiemc.entity.foxie.constants.FoxieActivities;
import me.m1chelle99.foxiemc.entity.foxie.constants.FoxieMovementSpeed;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.level.pathfinder.Path;
Expand Down Expand Up @@ -56,10 +55,7 @@ public void start() {
}

public void stop() {
var prey = this._foxie.huntControl.prey;
if (!EntitySelector.NO_CREATIVE_OR_SPECTATOR.test(prey))
this._foxie.huntControl.prey = null;

this._foxie.huntControl.prey = null;
this._foxie.setAggressive(false);
this._foxie.getNavigation().stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public boolean canContinueToUse() {

public void stop() {
this._foxie.huntControl.berries = null;
this._foxie.getNavigation().stop();
}

public void tick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public boolean canContinueToUse() {
public void start() {
this._foxie.aiControl.startActivity(FoxieActivities.SearchForFood);
}

public void stop() {
this._foxie.getNavigation().stop();
}

@Override
public void tick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public void stop() {
this._cooldown = 0;
if (this._foxie.aiControl.hasActivity(FoxieActivities.Panic))
this._foxie.aiControl.startActivity(FoxieActivities.None);

this._foxie.getNavigation().stop();
}

public boolean requiresUpdateEveryTick() {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/me/m1chelle99/foxiemc/events/ForgeServerEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import me.m1chelle99.foxiemc.FoxieMCMod;
import me.m1chelle99.foxiemc.entity.foxie.Foxie;
import me.m1chelle99.foxiemc.init.EntityInit;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.animal.Fox;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.MobSpawnSettings;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

Expand All @@ -18,4 +27,33 @@ public static void onEntityHurt(LivingHurtEvent event) {
if (event.getEntity() instanceof Foxie foxie)
foxie.aiControl.onHurt();
}

@SubscribeEvent
public static void onLivingSpawn(LivingSpawnEvent event) {
if (!(event.getEntity() instanceof Fox fox))
return;

var position = fox.blockPosition();
fox.remove(Entity.RemovalReason.DISCARDED);
var foxie = EntityInit.FOXIE.get();
var entity = foxie.create(fox.level);
if (entity == null)
return;

entity.setPos(position.getX(), position.getY(), position.getZ());
fox.level.addFreshEntity(entity);
}

@SubscribeEvent
public static void onBiomeLoading(BiomeLoadingEvent event) {
var spawners = event.getSpawns().getSpawner(MobCategory.CREATURE);
spawners.removeIf(x -> x.type == EntityType.FOX);

if (event.getCategory() != Biome.BiomeCategory.TAIGA)
return;

var foxie = EntityInit.FOXIE.get();
var foxieSpawnInfo = new MobSpawnSettings.SpawnerData(foxie, 10, 2, 4);
spawners.add(foxieSpawnInfo);
}
}

0 comments on commit c8b1095

Please sign in to comment.