Skip to content

Instantly share code, notes, and snippets.

@aikar
Created September 9, 2018 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aikar/eb146579560deb5fca7c6a641478ea12 to your computer and use it in GitHub Desktop.
Save aikar/eb146579560deb5fca7c6a641478ea12 to your computer and use it in GitHub Desktop.
private boolean flee() {
if (runAway == null || runAway.distance(entity.getLocation()) < 5) {
runAway = Util.getValidRandLocMinDist(8, entity.getLocation(), 14, 5, true);
}
if (runAway != null) {
entity.setTarget(null);
fleeing = false;
boolean result = API.entity.setEntityDestination(entity, runAway, 1.15);
fleeing = true;
return result;
}
return false;
}
@NotNull
private static PotionData boostType(PotionType type) {
return new PotionData(type, type.isExtendable() && !type.isUpgradeable(), type.isUpgradeable());
}
@EventHandler(ignoreCancelled = true)
public void onWitchReadyPotion(WitchReadyPotionEvent event) {
if (isFleeing()) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityTarget(EntityTargetEvent event) {
if (isFleeing() && event.getTarget() != null) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityPathfind(EntityPathfindEvent event) {
if (isFleeing() && runAway != null && runAway.distance(event.getLoc()) > 2) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityRandomStroll(EntityRandomStrollEvent event) {
if (entity.getTarget() != null || isFleeing()) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityPrepForRangedAttack(EntityPrepForRangedAttack event) {
if (isFleeing()) {
event.setCancelled(true);
}
}
@EventHandler(ignoreCancelled = true)
public void onEntityPathfindEnd(EntityPathfindEndEvent event) {
if (isFleeing()) {
double distance = runAway.distance(entity.getLocation());
if (distance < 3) {
runAway = null;
}
flee();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment