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


Java EntityLivingBase.addVelocity方法代码示例

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


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

示例1: onHurt

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@SubscribeEvent
public void onHurt(LivingHurtEvent ev) {
    DamageSource source = ev.getSource();
    Entity root = source.getImmediateSource();
    if (root instanceof EntityLivingBase) {
        EntityLivingBase cause = (EntityLivingBase) root;
        EntityLivingBase hurt = ev.getEntityLiving();

        EnumHand active = cause.getActiveHand();
        ItemStack stack = cause.getHeldItem(active);
        RandoresItemHelper.doEmpowered(stack, hurt, cause);

        if(stack.getItem() instanceof RandoresSledgehammer) {
            Vec3d vector = hurt.getPositionVector().subtract(cause.getPositionVector()).normalize().scale(2);
            hurt.addVelocity(vector.x, 0.5, vector.z);
        }
    }
}
 
开发者ID:Randores,项目名称:Randores2,代码行数:19,代码来源:LivingHurtListener.java

示例2: onImpact

import net.minecraft.entity.EntityLivingBase; //导入方法依赖的package包/类
@Override
protected void onImpact(RayTraceResult result) {
	if (result.typeOfHit == RayTraceResult.Type.ENTITY) {
		EntityLivingBase thrower = getThrower();
		// prevent damaging thrower
		if (result.entityHit == thrower)
			return;

		Entity entity = result.entityHit;
		DamageSource ds = createDamageSource(null == thrower ? this : thrower);

		if (isBurning() && !(entity instanceof EntityEnderman))
			entity.setFire(5);
		if (entity.attackEntityFrom(ds, getDamage())) {
			if (entity instanceof EntityLivingBase) {
				EntityLivingBase base = (EntityLivingBase) entity;

				if (knockbackStrength > 0) {
					float f1 = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
					if (f1 > 0f) {
						base.addVelocity(motionX * knockbackStrength * 0.6000000238418579D / f1,
							0.1D, motionZ * knockbackStrength * 0.6000000238418579D / f1);
					}
				}

				if (null != thrower) {
					EnchantmentHelper.applyThornEnchantments(base, thrower);
					EnchantmentHelper.applyArthropodEnchantments(thrower, base);
					if (base != thrower && base instanceof EntityPlayer && thrower instanceof EntityPlayerMP)
					{
						((EntityPlayerMP)thrower).connection.sendPacket(new SPacketChangeGameState(6, 0.0F));
					}
				}
			}
		}
	}
	if (!worldObj.isRemote)
        setDead();
}
 
开发者ID:arucil,项目名称:mc-Slingshot,代码行数:40,代码来源:EntityBall.java

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