use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method setSpeed.
@Override
public void setSpeed(Entity entity, double speed) {
net.minecraft.world.entity.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof Mob)) {
return;
}
Mob nmsEntity = (Mob) nmsEntityEntity;
nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity 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.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class DenizenNetworkManagerImpl method tryProcessTeleportPacketForAttach.
public void tryProcessTeleportPacketForAttach(ClientboundTeleportEntityPacket packet, Entity e, Vector relative) throws IllegalAccessException {
EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUUID());
if (attList != null) {
for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUUID());
if (attMap.attached.isValid() && att != null) {
ClientboundTeleportEntityPacket pNew = new ClientboundTeleportEntityPacket(copyPacket(packet));
ENTITY_ID_PACKTELENT.setInt(pNew, att.attached.getBukkitEntity().getEntityId());
Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew)).add(relative);
if (att.positionalOffset != null) {
resultPos = att.fixedForOffset(resultPos, e.getYRot(), e.getXRot());
byte yaw, pitch;
if (att.noRotate) {
Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
yaw = EntityAttachmentHelper.compressAngle(attachedEntity.getYRot());
pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
} else {
yaw = packet.getyRot();
pitch = packet.getxRot();
}
if (att.noPitch) {
Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
}
byte newYaw = EntityAttachmentHelper.adaptedCompressedAngle(yaw, att.positionalOffset.getYaw());
pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
POS_X_PACKTELENT.setDouble(pNew, resultPos.getX());
POS_Y_PACKTELENT.setDouble(pNew, resultPos.getY());
POS_Z_PACKTELENT.setDouble(pNew, resultPos.getZ());
YAW_PACKTELENT.setByte(pNew, newYaw);
PITCH_PACKTELENT.setByte(pNew, pitch);
if (NMSHandler.debugPackets) {
Debug.log("Attach Teleport Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with raw yaw " + yaw + " adapted to " + newYaw);
}
}
att.visiblePositions.put(player.getUUID(), resultPos.clone());
oldManager.send(pNew);
}
}
}
if (e.passengers != null && !e.passengers.isEmpty()) {
for (Entity ent : e.passengers) {
tryProcessTeleportPacketForAttach(packet, ent, new Vector(ent.getX() - e.getX(), ent.getY() - e.getY(), ent.getZ() - e.getZ()));
}
}
}
use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method sendRename.
@Override
public void sendRename(Player player, Entity entity, String name, boolean listMode) {
try {
if (entity.getType() == EntityType.PLAYER) {
if (listMode) {
send(player, new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME, ((CraftPlayer) player).getHandle()));
} else {
// For player entities, force a respawn packet and let the dynamic intercept correct the details
ChunkMap tracker = ((ServerLevel) ((CraftEntity) entity).getHandle().level).getChunkSource().chunkMap;
ChunkMap.TrackedEntity entityTracker = tracker.entityMap.get(entity.getEntityId());
if (entityTracker != null) {
try {
ServerEntity entry = (ServerEntity) ENTITY_TRACKER_ENTRY_GETTER.get(entityTracker);
if (entry != null) {
entry.removePairing(((CraftPlayer) player).getHandle());
entry.addPairing(((CraftPlayer) player).getHandle());
}
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
}
return;
}
SynchedEntityData fakeData = new SynchedEntityData(((CraftEntity) entity).getHandle());
ClientboundSetEntityDataPacket packet = new ClientboundSetEntityDataPacket(entity.getEntityId(), fakeData, false);
List<SynchedEntityData.DataItem<?>> list = new ArrayList<>();
list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_METADATA, Optional.of(Handler.componentToNMS(FormattedTextHelper.parse(name, ChatColor.WHITE)))));
list.add(new SynchedEntityData.DataItem<>(ENTITY_CUSTOM_NAME_VISIBLE_METADATA, true));
ENTITY_METADATA_LIST_SETTER.invoke(packet, list);
send(player, packet);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
use of org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity 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));
}
Aggregations