本文整理汇总了Java中net.minecraft.entity.EntityLivingBase.setRevengeTarget方法的典型用法代码示例。如果您正苦于以下问题:Java EntityLivingBase.setRevengeTarget方法的具体用法?Java EntityLivingBase.setRevengeTarget怎么用?Java EntityLivingBase.setRevengeTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.EntityLivingBase
的用法示例。
在下文中一共展示了EntityLivingBase.setRevengeTarget方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActiveItemUseTick
import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@SubscribeEvent
public void onActiveItemUseTick(LivingEntityUseItemEvent.Tick event) {
ItemStack stack = event.getItem();
if (stack.getItem() == TrumpetSkeletonItems.TRUMPET) {
if (event.getDuration() == stack.getMaxItemUseDuration() - 10) {
EntityLivingBase user = event.getEntityLiving();
World world = user.world;
user.playSound(TrumpetSkeletonSoundEvents.ITEM_TRUMPET_USE, 1.0F, 0.9F + world.rand.nextFloat() * 0.2F);
if (!world.isRemote) {
List<EntityLivingBase> spookedEntities = world.getEntitiesWithinAABB(EntityLivingBase.class, user.getEntityBoundingBox().grow(10.0D));
for (EntityLivingBase spookedEntity : spookedEntities) {
if (spookedEntity == user) continue;
double deltaX = user.posX - spookedEntity.posX;
double deltaZ = user.posZ - spookedEntity.posZ;
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
if (distance > 0.25D) {
spookedEntity.knockBack(user, 0.5F, deltaX / distance, deltaZ / distance);
}
spookedEntity.setRevengeTarget(user);
}
stack.damageItem(1, user);
}
} else if (event.getDuration() <= stack.getMaxItemUseDuration() - 15) {
event.setCanceled(true);
}
}
}