use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getSpeed.
@Override
public double getSpeed(Entity entity) {
net.minecraft.world.entity.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof Mob)) {
return 0.0;
}
Mob nmsEntity = (Mob) nmsEntityEntity;
return nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).getBaseValue();
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity 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.world.entity.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof Mob)) {
return;
}
final Mob nmsFollower = (Mob) nmsEntityFollower;
final PathNavigation 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.setSpeedModifier(2D);
Location targetLocation = target.getLocation();
Path 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.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.moveTo(path, 1D);
followerNavigation.setSpeedModifier(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.createPath(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.moveTo(path, 1D);
followerNavigation.setSpeedModifier(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.stop();
}
nmsFollower.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of org.openstreetmap.osmosis.core.domain.v0_6.Entity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method sendShowPacket.
@Override
public void sendShowPacket(Player pl, Entity entity) {
if (entity instanceof Player) {
pl.showPlayer(Denizen.getInstance(), (Player) entity);
return;
}
CraftPlayer craftPlayer = (CraftPlayer) pl;
ServerPlayer entityPlayer = craftPlayer.getHandle();
if (entityPlayer.connection != null && !craftPlayer.equals(entity)) {
ChunkMap tracker = ((ServerLevel) craftPlayer.getHandle().level).getChunkSource().chunkMap;
net.minecraft.world.entity.Entity other = ((CraftEntity) entity).getHandle();
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
if (entry != null) {
entry.removePlayer(entityPlayer);
entry.updatePlayer(entityPlayer);
}
}
}
Aggregations