use of net.minecraft.server.v1_16_R3.EntityInsentient in project UltraCosmetics by iSach.
the class EntityUtil method clearPathfinders.
@Override
public void clearPathfinders(Entity entity) {
EntityInsentient entitySheep = (EntityInsentient) ((CraftEntity) entity).getHandle();
try {
Field bField = PathfinderGoalSelector.class.getDeclaredField("b");
bField.setAccessible(true);
Field cField = PathfinderGoalSelector.class.getDeclaredField("c");
cField.setAccessible(true);
bField.set(entitySheep.goalSelector, new UnsafeList<PathfinderGoalSelector>());
bField.set(entitySheep.targetSelector, new UnsafeList<PathfinderGoalSelector>());
cField.set(entitySheep.goalSelector, new UnsafeList<PathfinderGoalSelector>());
cField.set(entitySheep.targetSelector, new UnsafeList<PathfinderGoalSelector>());
} catch (Exception exc) {
exc.printStackTrace();
}
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project UltraCosmetics by iSach.
the class EntityUtil method makePanic.
@Override
public void makePanic(Entity entity) {
EntityInsentient insentient = (EntityInsentient) ((CraftEntity) entity).getHandle();
insentient.goalSelector.a(3, new CustomPathFinderGoalPanic((EntityCreature) insentient, 0.4d));
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project UltraCosmetics by iSach.
the class PlayerFollower method follow.
@Override
public void follow(Player player) {
if (player == null) {
return;
}
if (UltraCosmeticsData.get().getPlugin().getPlayerManager().getUltraPlayer(player).getCurrentTreasureChest() != null) {
return;
}
Entity petEntity;
if (pet.isCustomEntity()) {
petEntity = ((CustomEntityPet) pet).getCustomEntity();
} else {
petEntity = ((CraftEntity) pet.getEntity()).getHandle();
}
if (petEntity == null) {
return;
}
// Run in sync... To enhance :S
Bukkit.getScheduler().runTask(UltraCosmeticsData.get().getPlugin(), () -> {
if (!player.isOnline())
return;
if (!player.getWorld().equals(petEntity.getBukkitEntity().getWorld())) {
petEntity.getBukkitEntity().teleport(player.getLocation());
return;
}
((EntityInsentient) petEntity).getNavigation().a(2d);
Location targetLocation = player.getLocation();
PathEntity path = ((EntityInsentient) petEntity).getNavigation().a(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1, 1);
try {
int distance = (int) Bukkit.getPlayer(player.getName()).getLocation().distance(petEntity.getBukkitEntity().getLocation());
if (distance > 10 && petEntity.valid && player.isOnGround()) {
petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
}
if (path != null && distance > 1.3) {
double speed = 1.15d;
if (pet.getType().getEntityType() == EntityType.ZOMBIE) {
speed *= 1.3;
}
((EntityInsentient) petEntity).getNavigation().a(path, speed);
((EntityInsentient) petEntity).getNavigation().a(speed);
}
} catch (IllegalArgumentException exception) {
petEntity.setLocation(targetLocation.getBlockX(), targetLocation.getBlockY(), targetLocation.getBlockZ(), 0, 0);
// exception.printStackTrace();
}
});
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method follow.
@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
if (target == null || follower == null) {
return;
}
final net.minecraft.server.v1_16_R3.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
UUID uuid = follower.getUniqueId();
if (followTasks.containsKey(uuid)) {
followTasks.get(uuid).cancel();
}
final int locationNearInt = (int) Math.floor(lead);
final boolean hasMax = maxRange > lead;
followTasks.put(follower.getUniqueId(), new BukkitRunnable() {
private boolean inRadius = false;
public void run() {
if (!target.isValid() || !follower.isValid()) {
this.cancel();
}
followerNavigation.a(2F);
Location targetLocation = target.getLocation();
PathEntity path;
if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
if (!inRadius) {
if (teleport) {
follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
} else {
cancel();
}
} else {
inRadius = false;
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.o();
}
nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method walkTo.
@Override
public void walkTo(final LivingEntity entity, Location location, Double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.server.v1_16_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
final PathEntity path;
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
entity.setAI(true);
try {
ENTITY_ONGROUND_SETTER.invoke(nmsEntity, true);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ(), 0);
if (path != null) {
entityNavigation.a(path, 1D);
entityNavigation.a(2D);
final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getBaseValue();
if (speed != null) {
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
new BukkitRunnable() {
@Override
public void run() {
if (!entity.isValid()) {
if (callback != null) {
callback.run();
}
cancel();
return;
}
if (aiDisabled && entity instanceof Wolf) {
((Wolf) entity).setAngry(false);
}
if (entityNavigation.m() || path.c()) {
if (callback != null) {
callback.run();
}
if (speed != null) {
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
}
if (aiDisabled) {
entity.setAI(false);
}
cancel();
}
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
} else // if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
// TODO: generate waypoints to the target location?
{
entity.teleport(location);
}
}
Aggregations