當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。