本文整理匯總了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);
}
}
}