Java Code Examples for net.minecraft.entity.damage.DamageSource#getSource()

The following examples show how to use net.minecraft.entity.damage.DamageSource#getSource() . 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: LivingEntityMixin.java    From the-hallow with MIT License 6 votes vote down vote up
@Inject(method = "drop(Lnet/minecraft/entity/damage/DamageSource;)V", at = @At("HEAD"))
public void drop(DamageSource damageSource, CallbackInfo info) {
	LivingEntity livingEntity = (LivingEntity) (Object) this;
	if (damageSource.getSource() instanceof LivingEntity && livingEntity.world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT) && BeheadingEnchantment.hasBeheading((LivingEntity) damageSource.getSource())) {
		if (BeheadingEnchantment.getHead(damageSource)) {
			if (livingEntity.getType() == EntityType.WITHER_SKELETON) {
				livingEntity.dropStack(new ItemStack(Items.WITHER_SKELETON_SKULL));
			} else if (livingEntity.getType() == EntityType.SKELETON) {
				livingEntity.dropStack(new ItemStack(Items.SKELETON_SKULL));
			} else if (livingEntity.getType() == EntityType.ZOMBIE) {
				livingEntity.dropStack(new ItemStack(Items.ZOMBIE_HEAD));
			} else if (livingEntity.getType() == EntityType.CREEPER) {
				livingEntity.dropStack(new ItemStack(Items.CREEPER_HEAD));
			} else if (livingEntity.getType() == EntityType.PLAYER) {
				livingEntity.dropStack(new ItemStack(Items.PLAYER_HEAD));
			}
		}
	}
}
 
Example 2
Source File: BeheadingEnchantment.java    From the-hallow with MIT License 5 votes vote down vote up
public static boolean getHead(DamageSource damageSource) {
	if (damageSource.getSource() instanceof LivingEntity && hasBeheading((LivingEntity) damageSource.getSource())) {
		LivingEntity attacker = (LivingEntity) damageSource.getSource();
		int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(HallowedEnchantments.BEHEADING, attacker);
		int scytheMultiplier = attacker.getActiveItem().getItem() == HallowedItems.REAPERS_SCYTHE ? 2 : 1;
		return attacker.world.random.nextInt(100) <= BEHEAD_CHANCE.get(enchantmentLevel - 1) * scytheMultiplier;
	} else {
		return false;
	}
}
 
Example 3
Source File: LifestealEnchantment.java    From the-hallow with MIT License 5 votes vote down vote up
public static float getLifeWithSteal(DamageSource damageSource, float damage, LivingEntity attackedEntity) {
	if (damageSource.getSource() instanceof LivingEntity && hasLifesteal((LivingEntity) damageSource.getSource()) && attackedEntity.getHealth() <= 0) {
		LivingEntity attacker = (LivingEntity) damageSource.getSource();
		int enchantmentLevel = EnchantmentHelper.getEquipmentLevel(HallowedEnchantments.LIFESTEAL, attacker);
		float stolenHealth = damage * STEAL_MULTIPLIER.get(enchantmentLevel);
		return Math.min(attacker.getMaximumHealth(), attacker.getHealth() + stolenHealth);
	} else {
		return 0;
	}
}
 
Example 4
Source File: LivingEntityMixin.java    From the-hallow with MIT License 5 votes vote down vote up
@Inject(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("RETURN"))
public void applyDamage(DamageSource damageSource, float damage, CallbackInfo info) {
	LivingEntity attacked = (LivingEntity) (Object) this;
	if (damageSource.getSource() instanceof LivingEntity && attacked.getHealth() < damage) {
		LivingEntity attacker = (LivingEntity) damageSource.getSource();
		if (!attacked.isInvulnerableTo(damageSource)) {
			float health = LifestealEnchantment.getLifeWithSteal(damageSource, damage, attacked);
			if (health != 0) {
				attacker.setHealth(health);
			}
		}
	}
}