use of net.minecraft.server.v1_16_R3.Path 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.Path in project dishevelled-bio by heuermh.
the class Gfa1ToGfa2 method call.
@Override
public Integer call() throws Exception {
PrintWriter writer = null;
try {
writer = writer(outputGfa2File);
final PrintWriter w = writer;
Gfa1Reader.stream(reader(inputGfa1File), new Gfa1Adapter() {
@Override
public boolean header(final Header header) {
// convert VN:Z:1.0 to VN:Z:2.0 annotation if present
if (header.getAnnotations().containsKey("VN")) {
if (!"1.0".equals(header.getAnnotations().get("VN").getValue())) {
throw new RuntimeException("cannot convert input as GFA 1.0, was " + header.getAnnotations().get("VN").getValue());
}
Map<String, Annotation> annotations = new HashMap<String, Annotation>();
annotations.put("VN", new Annotation("VN", "Z", "2.0"));
for (Annotation annotation : header.getAnnotations().values()) {
if (!"VN".equals(annotation.getName())) {
annotations.put(annotation.getName(), annotation);
}
}
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Header(annotations), w);
} else {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Header(header.getAnnotations()), w);
}
return true;
}
@Override
public boolean segment(final Segment segment) {
if (segment.getSequence() != null) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), segment.getSequence().length(), segment.getSequence(), segment.getAnnotations()), w);
} else if (segment.getAnnotations().containsKey("LN")) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), Integer.parseInt(segment.getAnnotations().get("LN").getValue()), segment.getSequence(), segment.getAnnotations()), w);
} else {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Segment(segment.getId(), 0, segment.getSequence(), segment.getAnnotations()), w);
}
return true;
}
@Override
public boolean link(final Link link) {
Position unknown = new Position(0, false);
Alignment alignment = link.getOverlap() == null ? null : Alignment.valueOf(link.getOverlap());
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Edge(null, toGfa2Reference(link.getSource()), toGfa2Reference(link.getTarget()), unknown, unknown, unknown, unknown, alignment, link.getAnnotations()), w);
return true;
}
@Override
public boolean containment(final Containment containment) {
Position unknown = new Position(0, false);
Position targetStart = new Position(containment.getPosition(), false);
Alignment alignment = containment.getOverlap() == null ? null : Alignment.valueOf(containment.getOverlap());
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Edge(null, toGfa2Reference(containment.getContainer()), toGfa2Reference(containment.getContained()), unknown, unknown, targetStart, unknown, alignment, containment.getAnnotations()), w);
return true;
}
@Override
public boolean path(final Path path) {
Gfa2Writer.write(new org.dishevelled.bio.assembly.gfa2.Path(path.getName(), toGfa2References(path.getSegments()), path.getAnnotations()), w);
return true;
}
});
return 0;
} finally {
try {
writer.close();
} catch (Exception e) {
// empty
}
}
}
use of net.minecraft.server.v1_16_R3.Path in project dishevelled-bio by heuermh.
the class TraversePaths method call.
@Override
public Integer call() throws Exception {
BufferedReader reader = null;
PrintWriter writer = null;
try {
reader = reader(inputGfa1File);
writer = writer(outputGfa1File);
final PrintWriter w = writer;
Gfa1Reader.stream(reader, new Gfa1Listener() {
@Override
public boolean record(final Gfa1Record gfa1Record) {
Gfa1Writer.write(gfa1Record, w);
if (gfa1Record instanceof Path) {
Path path = (Path) gfa1Record;
int size = path.getSegments().size();
Reference source = null;
Reference target = null;
String overlap = null;
for (int i = 0; i < size; i++) {
target = path.getSegments().get(i);
if (i > 0) {
overlap = (path.getOverlaps() != null && path.getOverlaps().size() > i) ? path.getOverlaps().get(i - 1) : null;
}
if (source != null) {
Traversal traversal = new Traversal(path.getName(), i - 1, source, target, overlap, EMPTY_ANNOTATIONS);
Gfa1Writer.write(traversal, w);
}
source = target;
}
}
return true;
}
});
return 0;
} finally {
try {
reader.close();
} catch (Exception e) {
// ignore
}
try {
writer.close();
} catch (Exception e) {
// ignore
}
}
}
use of net.minecraft.server.v1_16_R3.Path 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.Path 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