Search in sources :

Example 76 with CraftEntity

use of org.bukkit.craftbukkit.v1_6_R2.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()));
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Aggregations

Entity (org.bukkit.entity.Entity)30 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)17 UUID (java.util.UUID)12 CraftEntity (org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity)10 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)10 HashSet (java.util.HashSet)8 Set (java.util.Set)8 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)7 CraftEntity (org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity)7 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)6 Location (org.bukkit.Location)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 net.minecraft.server.v1_10_R1 (net.minecraft.server.v1_10_R1)5 net.minecraft.server.v1_11_R1 (net.minecraft.server.v1_11_R1)5 Entity (net.minecraft.world.entity.Entity)5 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)5 Vector (org.bukkit.util.Vector)5