Java Code Examples for net.minecraft.entity.EntityLivingBase#addVelocity()

The following examples show how to use net.minecraft.entity.EntityLivingBase#addVelocity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfinitePain.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onLanding(LivingFallEvent event) {
	EntityLivingBase elb = event.getEntityLiving();
	if(elb.hasItemInSlot(EntityEquipmentSlot.FEET) && elb.getItemStackFromSlot(EntityEquipmentSlot.FEET).getItem() == PAIN_BOOTS) {
		if(event.getDistance() >= minTriggerHeight) {

			boolean notObstructed = true;
			double impactPosition = 0;

			for(int i = (int) elb.posY + 2; i < elb.world.provider.getHeight(); i++) {
				BlockPos pos = new BlockPos(elb.posX, i, elb.posZ);
				IBlockState state = elb.world.getBlockState(pos);
				if(state.isFullBlock() || state.isFullCube()) {
					notObstructed = false;
					impactPosition = i;
					break;
				}
			}


			if(notObstructed) {
				elb.setPositionAndUpdate(elb.posX, elb.world.provider.getHeight() + heightToAdd, elb.posZ);
				event.setDamageMultiplier(0);
			} else {
				elb.addVelocity(0, (impactPosition - elb.posY) / 2, 0);
				elb.attackEntityFrom(DamageSource.GENERIC, damageOnImpact);
				event.setDamageMultiplier(0);
			}
		}
	}
}
 
Example 2
Source File: InfinitePain.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onLandingCreative(PlayerFlyableFallEvent event) {
	EntityLivingBase elb = event.getEntityLiving();
	if(elb.hasItemInSlot(EntityEquipmentSlot.FEET) && elb.getItemStackFromSlot(EntityEquipmentSlot.FEET).getItem() == PAIN_BOOTS) {
		if(event.getDistance() >= minTriggerHeight) {

			boolean notObstructed = true;
			double impactPosition = 0;

			for(int i = (int) elb.posY + 2; i < elb.world.provider.getHeight(); i++) {
				BlockPos pos = new BlockPos(elb.posX, i, elb.posZ);
				IBlockState state = elb.world.getBlockState(pos);
				if(state.isFullBlock() || state.isFullCube()) {
					notObstructed = false;
					impactPosition = i;
					break;
				}
			}


			if(notObstructed) {
				elb.setPositionAndUpdate(elb.posX, elb.world.provider.getHeight() + heightToAdd, elb.posZ);
			} else {
				elb.addVelocity(0, (impactPosition - elb.posY) / 2, 0);
			}
		}
	}
}
 
Example 3
Source File: EntityMage.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
private void attackWithForce(EntityLivingBase target) {
	setStaffAttacking(true);

	double force = 8;

	double relX = target.posX - this.posX;
	double relZ = target.posZ - this.posZ;

	double mag = Math.sqrt((relX * relX) + (relZ * relZ));

	double forceX = force * (relX / mag);
	double forceZ = force * (relZ / mag);

	target.addVelocity(forceX, 1, forceZ);
	target.velocityChanged = true;

	this.playSound(SoundEvents.ENTITY_ENDERDRAGON_FLAP, 1.0F, 0.5F);
}