Java Code Examples for net.minecraft.entity.player.EntityPlayer#attackEntityFrom()

The following examples show how to use net.minecraft.entity.player.EntityPlayer#attackEntityFrom() . 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: MetaTileEntityRotorHolder.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean onRotorHolderInteract(EntityPlayer player) {
    if (player.capabilities.isCreativeMode) {
        return false;
    }
    if (!getWorld().isRemote && isRotorLooping) {
        double relativeSpeed = getRelativeRotorSpeed();
        float damageApplied = (float) (DAMAGE_PER_INTERACT * relativeSpeed);
        player.attackEntityFrom(DamageSources.getTurbineDamage(), damageApplied);
        //TODO achievement here
        return true;
    }
    return isRotorLooping;
}
 
Example 2
Source File: HazardousItemsHandler.java    From NewHorizonsCoreMod with GNU General Public License v3.0 5 votes vote down vote up
private void DoHIEffects( IDamageEffectContainer pHI, EntityPlayer pPlayer )
{
  // Attack player based on all defined items
  for( HazardousItems.ItmDamageEffect iDE : pHI.getDamageEffects() ) {
      pPlayer.attackEntityFrom(DamageTypeHelper.ParseStringToDamageSource(iDE.getDamageSource()), iDE.getAmount());
  }

  for( HazardousItems.ItmPotionEffect iPE : pHI.getPotionEffects() ) {
      pPlayer.addPotionEffect(new PotionEffect(iPE.getId(), iPE.getDuration(), iPE.getLevel()));
  }
}
 
Example 3
Source File: EntityDireSlime.java    From EnderZoo with Creative Commons Zero v1.0 Universal 5 votes vote down vote up
@Override
public void onCollideWithPlayer(EntityPlayer p_70100_1_) {
  int i = getSlimeSize();
  if (canEntityBeSeen(p_70100_1_) && this.getDistanceSqToEntity(p_70100_1_) < (double) i * (double) i
      && p_70100_1_.attackEntityFrom(DamageSource.causeMobDamage(this), getAttackStrength())) {
    playSound(SoundEvents.ENTITY_SLIME_ATTACK, 1.0F, (rand.nextFloat() - rand.nextFloat()) * 0.2F + 1.0F);
  }
}
 
Example 4
Source File: PacketSecurityStationFailedHack.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handleServerSide(PacketSecurityStationFailedHack message, EntityPlayer player){
    TileEntity te = message.getTileEntity(player.worldObj);
    if(te instanceof TileEntitySecurityStation) {
        TileEntitySecurityStation station = (TileEntitySecurityStation)te;
        if(!station.isPlayerOnWhiteList(player)) {
            player.attackEntityFrom(DamageSourcePneumaticCraft.securityStation, 19);
        }
    }
}
 
Example 5
Source File: EntitySpiritWight.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onUpdate() {
	super.onUpdate();
	if (isAIDisabled()) return;

	if ((ticksExisted % RandUtil.nextInt(100, 200)) == 0)
		playSound(ModSounds.HALLOWED_SPIRIT, RandUtil.nextFloat(), RandUtil.nextFloat());

	fallDistance = 0;

	EntityPlayer farPlayer = world.getNearestPlayerNotCreative(this, 300);
	setAttackTarget(farPlayer);
	if (getAttackTarget() != null) {
		noClip = true;
		Vec3d direction = getPositionVector().subtract(getAttackTarget().getPositionVector()).normalize();
		motionX = direction.x * -0.1;
		motionY = direction.y * -0.1;
		motionZ = direction.z * -0.1;
		rotationYaw = (float) (((-MathHelper.atan2(direction.x, direction.z) * 180) / Math.PI) - 180) / 2;
	} else {
		if (!collidedVertically) {
			motionY = 0;
		}
		noClip = false;
	}

	EntityPlayer player = getAttackTarget() == null ? null : world.getNearestPlayerNotCreative(this, 2);
	EntityPlayer closePlayer = getAttackTarget() == null ? null : world.getNearestPlayerNotCreative(this, 30);
	boolean angry = player != null;

	ClientRunnable.run(new ClientRunnable() {
		@Override
		@SideOnly(Side.CLIENT)
		public void runIfClient() {
			if ((closePlayer != null) && !angry)
				LibParticles.SPIRIT_WIGHT_FLAME_FAR(world, getPositionVector().add(0, getEyeHeight(), 0));
			else if (angry)
				LibParticles.SPIRIT_WIGHT_FLAME_CLOSE(world, getPositionVector().add(0, getEyeHeight(), 0));
			else LibParticles.SPIRIT_WIGHT_FLAME_NORMAL(world, getPositionVector().add(0, getEyeHeight(), 0));
		}
	});

	if (angry) {
		player.attackEntityFrom(DamageSource.MAGIC, 0.15f);
		player.hurtResistantTime = 0;
	}
}