use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_11_R1 method walkTo.
@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.server.v1_11_R1.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 = isAIDisabled(entity);
if (aiDisabled) {
toggleAI(entity, true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
if (path != null) {
entityNavigation.a(path, 1D);
entityNavigation.a(2D);
final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
new BukkitRunnable() {
@Override
public void run() {
if (entityNavigation.n() || path.b()) {
if (callback != null) {
callback.run();
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, 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);
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MyPet by xXKeyleXx.
the class PlatformHelper method entityToTag.
@Override
public TagCompound entityToTag(Entity bukkitEntity) {
net.minecraft.server.v1_16_R1.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);
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MyPet by xXKeyleXx.
the class PlatformHelper method applyTagToEntity.
@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag);
if (vanillaNBT != null) {
if (bukkitEntity instanceof Villager) {
net.minecraft.world.entity.npc.Villager villager = (net.minecraft.world.entity.npc.Villager) entity;
villager.readAdditionalSaveData(vanillaNBT);
} else if (bukkitEntity instanceof net.minecraft.world.entity.npc.WanderingTrader) {
net.minecraft.world.entity.npc.WanderingTrader villager = (net.minecraft.world.entity.npc.WanderingTrader) entity;
villager.addAdditionalSaveData(vanillaNBT);
}
}
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project MyPet by xXKeyleXx.
the class PlatformHelper method entityToTag.
@Override
public TagCompound entityToTag(Entity bukkitEntity) {
net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
CompoundTag vanillaNBT = new CompoundTag();
if (entity instanceof net.minecraft.world.entity.LivingEntity) {
((net.minecraft.world.entity.LivingEntity) entity).addAdditionalSaveData(vanillaNBT);
} else {
Method b = ReflectionUtil.getMethod(entity.getClass(), "b", CompoundTag.class);
try {
b.invoke(entity, vanillaNBT);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
return (TagCompound) ItemStackNBTConverter.vanillaCompoundToCompound(vanillaNBT);
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity in project Citizens2 by CitizensDev.
the class NMSImpl method removeFromWorld.
@Override
public void removeFromWorld(org.bukkit.entity.Entity entity) {
Preconditions.checkNotNull(entity);
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.world.removeEntity(nmsEntity);
}
Aggregations