Search in sources :

Example 6 with net.minecraft.server.v1_16_R3

use of net.minecraft.server.v1_16_R3 in project MyPet by xXKeyleXx.

the class PlatformHelper method entityToTag.

@Override
public TagCompound entityToTag(Entity bukkitEntity) {
    net.minecraft.server.v1_16_R3.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    NBTTagCompound vanillaNBT = new NBTTagCompound();
    if (entity instanceof EntityLiving) {
        ((EntityLiving) entity).saveData(vanillaNBT);
    } else {
        Method b = ReflectionUtil.getMethod(entity.getClass(), "b", NBTTagCompound.class);
        try {
            b.invoke(entity, vanillaNBT);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return (TagCompound) ItemStackNBTConverter.vanillaCompoundToCompound(vanillaNBT);
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) Method(java.lang.reflect.Method) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with net.minecraft.server.v1_16_R3

use of net.minecraft.server.v1_16_R3 in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method resetEquipment.

@Override
public void resetEquipment(Player player, LivingEntity entity) {
    EntityEquipment equipment = entity.getEquipment();
    ArrayList<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> pairList = new ArrayList<>();
    pairList.add(new Pair<>(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(equipment.getItemInMainHand())));
    pairList.add(new Pair<>(EnumItemSlot.OFFHAND, CraftItemStack.asNMSCopy(equipment.getItemInOffHand())));
    pairList.add(new Pair<>(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(equipment.getHelmet())));
    pairList.add(new Pair<>(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(equipment.getChestplate())));
    pairList.add(new Pair<>(EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(equipment.getLeggings())));
    pairList.add(new Pair<>(EnumItemSlot.FEET, CraftItemStack.asNMSCopy(equipment.getBoots())));
    sendPacket(player, new PacketPlayOutEntityEquipment(entity.getEntityId(), pairList));
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityEquipment(org.bukkit.inventory.EntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 8 with net.minecraft.server.v1_16_R3

use of net.minecraft.server.v1_16_R3 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));
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Location(org.bukkit.Location)

Example 9 with net.minecraft.server.v1_16_R3

use of net.minecraft.server.v1_16_R3 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);
    }
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3)

Aggregations

net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)9 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 ItemStack (org.bukkit.inventory.ItemStack)2 CraftFakePlayerImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.CraftFakePlayerImpl)1 EntityItemProjectileImpl (com.denizenscript.denizen.nms.v1_16.impl.entities.EntityItemProjectileImpl)1 EntityTag (com.denizenscript.denizen.objects.EntityTag)1 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)1 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)1 Mechanism (com.denizenscript.denizencore.objects.Mechanism)1 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 Pair (com.mojang.datafixers.util.Pair)1 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)1 TagCompound (de.keyle.knbt.TagCompound)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Location (org.bukkit.Location)1 AttributeInstance (org.bukkit.attribute.AttributeInstance)1 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)1