Search in sources :

Example 66 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityControllerPet method repeatTask.

@Override
public void repeatTask() {
    super.repeatTask();
    if (!this.isInvisible())
        this.setInvisible(true);
    if (getPet() != null)
        if (isBaby())
            setBaby((getPet().getPetType() instanceof ShulkerDefault));
    Player p = getPet().getOwner();
    if (hasCustomName()) {
        setCustomNameVisible(false);
        if (displayEntity.getPassenger() != null) {
            this.displayEntity.getPassenger().setCustomName(getCustomName());
            this.displayEntity.getPassenger().setCustomNameVisible(true);
        } else {
            this.displayEntity.setCustomName(getCustomName());
            this.displayEntity.setCustomNameVisible(true);
        }
    }
    if (this.displayEntity != null) {
        if (this.displayEntity.isValid()) {
            if (displayEntity.getPassenger() == null) {
                reloadLocation();
                net.minecraft.server.v1_11_R1.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
                if (((CraftPlayer) getOwner()).getHandle().isInvisible() != displayEntity.isInvisible()) {
                    displayEntity.setInvisible(!displayEntity.isInvisible());
                }
                return;
            }
            if (this.displayEntity.getPassenger() != null) {
                net.minecraft.server.v1_11_R1.Entity displayEntity = ((CraftEntity) this.displayEntity.getPassenger()).getHandle();
                if (((CraftPlayer) p).getHandle().isInvisible() != displayEntity.isInvisible()) {
                    displayEntity.setInvisible(!displayEntity.isInvisible());
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) ShulkerDefault(simplepets.brainsynder.pet.types.ShulkerDefault) net.minecraft.server.v1_11_R1(net.minecraft.server.v1_11_R1) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)

Example 67 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityPet method e.

/**
 * This method handles the Pet riding
 *
 * NMS Translations (Thanks Forge):
 *   a(float,float,float) = travel(float,float,float)
 *   aF = prevLimbSwingAmount
 *   aG = limbSwingAmount
 *   aR = jumpMovementFactor
 *
 * Search for: !this.isInWater() || this instanceof EntityHuman && ((EntityHuman)this).abilities.isFlying
 * Class: {@link net.minecraft.server.v1_15_R1.EntityLiving}
 */
@Override
public // public void a(float strafe, float vertical, float forward) {
void e(Vec3D vec3D) {
    double strafe = vec3D.x;
    double vertical = vec3D.y;
    double forward = vec3D.z;
    if (passengers == null) {
        this.H = (float) 0.5;
        this.aM = (float) 0.02;
        super.a(vec3D);
    } else {
        if (this.pet == null) {
            this.H = (float) 0.5;
            this.aM = (float) 0.02;
            super.e(vec3D);
            return;
        }
        if (!isOwnerRiding()) {
            this.H = (float) 0.5;
            this.aM = (float) 0.02;
            super.e(vec3D);
            return;
        }
        EntityPlayer owner = ((CraftPlayer) getOwner()).getHandle();
        if (fieldAccessor != null) {
            if (fieldAccessor.hasField(owner)) {
                if (fieldAccessor.get(owner)) {
                    if (isOnGround(this)) {
                        setMot(getMot().x, 0.5, getMot().z);
                    } else {
                        if (pet.getPetType().canFly(pet.getOwner())) {
                            setMot(getMot().x, 0.3, getMot().z);
                        }
                    }
                }
            }
        }
        this.yaw = owner.yaw;
        this.lastYaw = this.yaw;
        this.pitch = (float) (owner.pitch * 0.5);
        this.setYawPitch(this.yaw, this.pitch);
        this.aL = this.aD = this.yaw;
        this.H = 1.0F;
        strafe = (float) (owner.aZ * 0.5);
        forward = owner.bb;
        if (forward <= 0.0) {
            forward *= 0.25;
        }
        Vec3D vec = new Vec3D(strafe, vertical, forward);
        // if (!(this instanceof IEntityHorsePet)) vec3D.vec3D.x *= 0.75;
        this.o((float) getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getValue());
        super.e(vec);
        if (!world.isClientSide) {
            if (this instanceof IEntityHorsePet) {
                Location location = getBukkitEntity().getLocation();
                setPosition(location.getX(), location.getY(), location.getZ());
                PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(this);
                owner.playerConnection.sendPacket(packet);
                if (forward > 0.0F) {
                    float f = MathHelper.sin((float) (this.yaw * 0.017453292));
                    float f1 = MathHelper.cos((float) (this.yaw * 0.017453292));
                    // This would be 0 anyways?
                    setMot(getMot().add((-0.4 * f * 0.0), 0, (0.4 * f1 * 0.0)));
                }
                // this.prevLimbSwingAmount = this.limbSwingAmount;
                this.aC = this.aD;
                double d0 = this.locX() - this.lastX;
                double d1 = this.locZ() - this.lastZ;
                float f5 = (float) (MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0);
                if (f5 > 1.0) {
                    f5 = (float) 1.0;
                }
                // this.limbSwingAmount += (f5 - this.limbSwingAmount) * 0.4F;
                this.aD += (f5 - this.aD) * 0.4;
                // this.limbSwing += this.limbSwingAmount;
                this.aE += this.aD;
            }
        }
        CraftEntity bukkitEntity = getBukkitEntity();
        if (pet == null) {
            if (bukkitEntity != null)
                bukkitEntity.remove();
            return;
        }
        if (getOwner() == null) {
            if (bukkitEntity != null)
                bukkitEntity.remove();
            return;
        }
        try {
            PetMoveEvent event = new PetMoveEvent(this, PetMoveEvent.Cause.RIDE);
            Bukkit.getServer().getPluginManager().callEvent(event);
        } catch (Throwable ignored) {
        }
    }
}
Also used : PetMoveEvent(simplepets.brainsynder.api.event.pet.PetMoveEvent) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) IEntityHorsePet(simplepets.brainsynder.api.entity.passive.IEntityHorsePet) Location(org.bukkit.Location)

Example 68 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityControllerPet method reloadLocation.

@Override
public void reloadLocation() {
    if (displayEntity.getPassenger() != null) {
        net.minecraft.server.v1_15_R1.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
        Location loc;
        if (this.displayRider != null) {
            if (this.displayRider.getType().equals(EntityType.SHULKER)) {
                loc = getBukkitEntity().getLocation().clone().subtract(0, 0.735, 0);
            } else {
                loc = getBukkitEntity().getLocation().clone();
            }
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
        displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
        loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
            }
        });
        return;
    }
    net.minecraft.server.v1_15_R1.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
    Location loc;
    if (this.displayRider != null) {
        if (this.displayRider.getType().equals(EntityType.SHULKER)) {
            loc = getBukkitEntity().getLocation().clone().add(0, 0.75, 0);
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
    } else {
        loc = getBukkitEntity().getLocation().clone();
    }
    displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    });
}
Also used : net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) CraftEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) Location(org.bukkit.Location)

Example 69 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project UltraCosmetics by iSach.

the class EntityUtil method sendDestroyPacket.

@Override
public void sendDestroyPacket(Player player, org.bukkit.entity.Entity entity) {
    ClientboundRemoveEntitiesPacket packet = new ClientboundRemoveEntitiesPacket(((CraftEntity) entity).getHandle().getId());
    ((CraftPlayer) player).getHandle().connection.send(packet);
}
Also used : ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)

Example 70 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project UltraCosmetics by iSach.

the class EntityUtil method follow.

@Override
public void follow(org.bukkit.entity.Entity toFollow, org.bukkit.entity.Entity follower) {
    Entity pett = ((CraftEntity) follower).getHandle();
    ((Mob) pett).getNavigation().setMaxVisitedNodesMultiplier(2);
    Object petf = ((CraftEntity) follower).getHandle();
    Location targetLocation = toFollow.getLocation();
    Path path;
    path = ((Mob) petf).getNavigation().createPath(targetLocation.getX() + 1, targetLocation.getY(), targetLocation.getZ() + 1, 1);
    if (path != null) {
        ((Mob) petf).getNavigation().moveTo(path, 1.05D);
        ((Mob) petf).getNavigation().setSpeedModifier(1.05D);
    }
}
Also used : Path(net.minecraft.world.level.pathfinder.Path) LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ChestBlockEntity(net.minecraft.world.level.block.entity.ChestBlockEntity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) EnderChestBlockEntity(net.minecraft.world.level.block.entity.EnderChestBlockEntity) PathfinderMob(net.minecraft.world.entity.PathfinderMob) Mob(net.minecraft.world.entity.Mob) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)41 Entity (org.bukkit.entity.Entity)38 LivingEntity (org.bukkit.entity.LivingEntity)37 Entity (net.minecraft.world.entity.Entity)25 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)25 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)24 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)22 Iterator (java.util.Iterator)21 List (java.util.List)21 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)21 UUID (java.util.UUID)20 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)20 Player (org.bukkit.entity.Player)16 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)14 Vector (org.bukkit.util.Vector)14 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)12 Vec3 (net.minecraft.world.phys.Vec3)12 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)11 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10