当前位置: 首页>>代码示例>>Java>>正文


Java EntityLivingBase.knockBack方法代码示例

本文整理汇总了Java中net.minecraft.entity.EntityLivingBase.knockBack方法的典型用法代码示例。如果您正苦于以下问题:Java EntityLivingBase.knockBack方法的具体用法?Java EntityLivingBase.knockBack怎么用?Java EntityLivingBase.knockBack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.entity.EntityLivingBase的用法示例。


在下文中一共展示了EntityLivingBase.knockBack方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: knockBackEntity

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
public static void knockBackEntity(EntityPlayer player, EntityLivingBase target) {
	double d1 = player.posX - target.posX;
	double d0;

	for (d0 = player.posZ - target.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D) {
		d1 = (Math.random() - Math.random()) * 0.01D;
	}

	target.attackedAtYaw = (float) (MathUtils.atan2(d0, d1) * (180D / Math.PI) - target.rotationYaw);
	target.knockBack(player, 1.0F, d1, d0);
}
 
开发者ID:p455w0rd,项目名称:EndermanEvolution,代码行数:12,代码来源:EntityUtils.java

示例2: onExecutionStart

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
	if (player.getActiveItemStack().isEmpty())
	{
		return;
	}
	
	Vec3d look = player.getLookVec().scale(5);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	EntityLivingBase assumedToBeLookedAt = Helpers.getClosest(targets, player);
	if (assumedToBeLookedAt != null)
	{
		if (!player.world.isRemote)
		{
			assumedToBeLookedAt.addPotionEffect(new PotionEffect(ExPPotions.stunned, 40, 0, false, false));
		}
		
		player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1, 0.1F);
		Vec3d targetPos = assumedToBeLookedAt.getPositionVector();
		assumedToBeLookedAt.knockBack(player, 2, pos.x - targetPos.x, pos.z - targetPos.z);
	}
	
	player.getActiveItemStack().damageItem(3, player);
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:27,代码来源:ShieldSlam.java

示例3: onExecutionStart

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
	ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
	EnumWeaponWeight weight = EnumWeaponWeight.getWeaponWeight(is);
	player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 1F);
	Vec3d look = player.getLookVec().scale(5);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	EntityLivingBase assumedToBeLookedAt = Helpers.getClosest(targets, player);
	if (assumedToBeLookedAt != null)
	{
		if (!player.world.isRemote)
		{
			assumedToBeLookedAt.addPotionEffect(new PotionEffect(ExPPotions.stunned, weight == EnumWeaponWeight.NORMAL ? 20 : 30, 0, false, false));
		}
		
		player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1, 1F);
		Vec3d targetPos = assumedToBeLookedAt.getPositionVector();
		assumedToBeLookedAt.knockBack(player, 1, pos.x - targetPos.x, pos.z - targetPos.z);
		for (int i = 0; i < 50; ++i)
		{
			player.world.spawnParticle(EnumParticleTypes.CRIT_MAGIC, targetPos.x + player.world.rand.nextDouble() - player.world.rand.nextDouble(), targetPos.z + assumedToBeLookedAt.getEyeHeight() + player.world.rand.nextDouble() - player.world.rand.nextDouble(), targetPos.z + player.world.rand.nextDouble() - player.world.rand.nextDouble(), 0, -0.1, 0);
		}
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:27,代码来源:DownStrike.java

示例4: 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);
        }
    }
}
 
开发者ID:JamiesWhiteShirt,项目名称:trumpet-skeleton,代码行数:29,代码来源:TrumpetSkeleton.java

示例5: onExecutionStart

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
	ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
	EnumWeaponWeight weight = EnumWeaponWeight.getWeaponWeight(is);
	player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 1F);
	Vec3d look = player.getLookVec().scale(6);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	for (EntityLivingBase target : targets)
	{
		Vec3d targetPos = target.getPositionVector();
		target.knockBack(player, 3, pos.x - targetPos.x, pos.z - targetPos.z);
		double distance = Math.max(0.3, targetPos.distanceTo(pos));
		target.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) (player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue() * (1 - (distance / 6))));
		player.world.playSound(player, target.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, SoundCategory.PLAYERS, 1, 2F);
		if (!player.world.isRemote && weight == EnumWeaponWeight.HEAVY && player.world.rand.nextDouble() <= 0.25)
		{
			target.addPotionEffect(new PotionEffect(ExPPotions.stunned, 100, 0, false, false));
		}
	}
	
	player.motionX += look.x / 5;
	player.motionZ += look.z / 5;
	for (int i = 0; i < 50; ++i)
	{
		double randomMagnitude = player.world.rand.nextDouble();
		Vec3d at = new Vec3d(pos.x + look.x * randomMagnitude, pos.y + player.getEyeHeight() - 0.25 + look.y * randomMagnitude, pos.z + look.z * randomMagnitude);
		player.world.spawnParticle(EnumParticleTypes.CRIT, at.x, at.y, at.z, 0, 0, 0);
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:32,代码来源:PiercingDash.java

示例6: updateTask

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
public void updateTask() {
	EntityLivingBase target=this.host.getAttackTarget();
	World world=this.host.world;
	this.host.getLookHelper().setLookPositionWithEntity(target, 30F, 90F);
	if(attackDuration<20){
		this.host.getNavigator().tryMoveToEntityLiving(target, 1f);
	}
	if(--this.attackDuration<=0){
		
		this.host.swingArm(EnumHand.MAIN_HAND);
		if(this.attacksMade>0&&this.attacksMade%13==0){
			this.host.setBombSpell(true);
			this.host.bombDuration=200;
			BlockPos pos = this.host.world.getTopSolidOrLiquidBlock(this.host.getPosition());
			this.host.topBlock=pos.getY()+7+this.host.rand.nextInt(3);
			this.attackDuration=200;
		}
		else if(this.attacksMade%2==0){
			this.attackDuration=20-this.host.level/4;
			if(this.host.getDistanceSqToEntity(target)<6){
				if(this.host.attackEntityAsMob(target)){
					target.knockBack(this.host, (float)1.5f, (double)MathHelper.sin(this.host.rotationYaw * 0.017453292F), (double)(-MathHelper.cos(this.host.rotationYaw * 0.017453292F)));
				}
			}
			else{
			((ItemProjectileWeapon) this.host.getHeldItemMainhand().getItem()).shoot(
					this.host.getHeldItemMainhand(), this.host, world, 0, EnumHand.MAIN_HAND);
			}
		}
		else{
			this.attackDuration=(int) (55/(0.92+this.host.level*0.08f));
			this.host.getNavigator().clearPathEntity();
			this.host.playSound(TF2Sounds.MOB_MERASMUS_SPELL, 2F, 1F);
			boolean attacked=false;
			for(EntityLivingBase living:world.getEntitiesWithinAABB(EntityLivingBase.class, this.host.getEntityBoundingBox().grow(12, 5, 12), new Predicate<EntityLivingBase>(){

				@Override
				public boolean apply(EntityLivingBase input) {
					// TODO Auto-generated method stub
					return input.getDistanceSqToEntity(host)<144&&!TF2Util.isOnSameTeam(host, input)&&EntityAITarget.isSuitableTarget(host, input, false, false);
				}
				
			})){
				living.attackEntityFrom(new EntityDamageSource("magicm",this.host).setMagicDamage().setDifficultyScaled(), 6);
				living.addVelocity(0, 1.25, 0);
				living.fallDistance=-10;
				attacked=true;
			}
			if(!attacked)
				this.host.teleportCooldown-=20;
		}
		this.attacksMade++;
	}
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:56,代码来源:EntityMerasmus.java


注:本文中的net.minecraft.entity.EntityLivingBase.knockBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。