Skip to content

Commit

Permalink
fix: Attraction Scroll working
Browse files Browse the repository at this point in the history
  • Loading branch information
darksonic300 committed Aug 2, 2024
1 parent 72320fa commit b8d146b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/main/java/com/github/darksonic300/seidr/event/SeidrEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.projectile.Fireball;
import net.minecraft.world.entity.projectile.SmallFireball;
Expand All @@ -38,6 +39,7 @@ public static void listen(IEventBus bus) {
bus.addListener(SeidrEvents::checkForAttractionScroll);

bus.addListener(SeidrEvents::removeAttraction);
bus.addListener(SeidrEvents::expireAttraction);
}


Expand Down Expand Up @@ -127,12 +129,12 @@ public static void checkForWalkingScroll(LivingEntityUseItemEvent event) {
}
}

public static void removeAttraction(MobEffectEvent.Expired event){
List<? extends Animal> list = event.getEntity().level().getEntitiesOfClass(Animal.class, event.getEntity().getBoundingBox().inflate(15, 5, 15));
for (Animal animal : list) {
animal.goalSelector.removeGoal(new FollowOwnerSummonGoal(animal, event.getEntity(), 1.1f, 5.0f, 2.0f));
event.getEntity().sendSystemMessage(Component.literal(animal.goalSelector.getAvailableGoals().toString()));
}
public static void expireAttraction(MobEffectEvent.Expired event){
removeGoal(event.getEntity(), event);
}

public static void removeAttraction(MobEffectEvent.Remove event){
removeGoal(event.getEntity(), event);
}

// Utility Methods
Expand All @@ -151,4 +153,15 @@ private static void summonZombie(Level level, LivingEntity entity, int number){
}
}

private static void removeGoal(LivingEntity entity, MobEffectEvent event) {
List<? extends Animal> list = entity.level().getEntitiesOfClass(Animal.class, entity.getBoundingBox().inflate(15, 5, 15));
for (Animal animal : list) {
for (WrappedGoal wrappedgoal : animal.goalSelector.getAvailableGoals())
if (wrappedgoal.getGoal() instanceof FollowOwnerSummonGoal)
wrappedgoal.stop();

animal.goalSelector.getAvailableGoals().removeIf(goal -> goal.getGoal() instanceof FollowOwnerSummonGoal);
}
}

}

0 comments on commit b8d146b

Please sign in to comment.