use of net.minecraft.util.DamageSource in project NetherEx by LogicTechCorp.
the class EventHandler method onLivingAttacked.
@SubscribeEvent
public static void onLivingAttacked(LivingAttackEvent event) {
EntityLivingBase entity = (EntityLivingBase) event.getEntity();
World world = entity.getEntityWorld();
BlockPos pos = entity.getPosition();
DamageSource source = event.getSource();
if (source.isFireDamage()) {
if (!entity.isImmuneToFire() && entity.isRiding() && entity.getRidingEntity() instanceof EntityObsidianBoat) {
event.setCanceled(true);
}
}
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
if (source.isFireDamage()) {
if (ArmorUtil.isWearingFullArmorSet(player, NetherExMaterials.ARMOR_HIDE_SALAMANDER)) {
event.setCanceled(true);
}
}
if (player.dimension == -1) {
if (source == DamageSource.LAVA && player.isPotionActive(MobEffects.FIRE_RESISTANCE)) {
player.addStat(NetherExAchievements.STAYIN_FROSTY);
}
}
}
}
use of net.minecraft.util.DamageSource in project NetherEx by LogicTechCorp.
the class EventHandler method onLivingDeath.
@SubscribeEvent
public static void onLivingDeath(LivingDeathEvent event) {
Entity entity = event.getEntity();
World world = entity.getEntityWorld();
BlockPos pos = entity.getPosition();
DamageSource source = event.getSource();
if (entity instanceof AbstractSkeleton) {
if (source.getSourceOfDamage() instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) source.getSourceOfDamage();
if (ArmorUtil.isWearingFullArmorSet(player, NetherExMaterials.ARMOR_BONE_WITHERED)) {
player.addStat(NetherExAchievements.FROM_WITHIN);
}
}
}
}
use of net.minecraft.util.DamageSource in project SpongeCommon by SpongePowered.
the class DamageSourceRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
try {
// These need to be instantiated after the DamageTypeRegistryModule has had a chance to register
// the damage types, otherwise it will fail and have invalid types.
DAMAGESOURCE_POISON = (new DamageSource("poison")).setDamageBypassesArmor().setMagicDamage();
DAMAGESOURCE_MELTING = (new DamageSource("melting")).setDamageBypassesArmor().setFireDamage();
IGNORED_DAMAGE_SOURCE = new DamageSource("spongespecific").setDamageBypassesArmor().setDamageAllowedInCreativeMode();
DamageSources.class.getDeclaredField("DROWNING").set(null, DamageSource.DROWN);
DamageSources.class.getDeclaredField("FALLING").set(null, DamageSource.FALL);
DamageSources.class.getDeclaredField("FIRE_TICK").set(null, DamageSource.ON_FIRE);
DamageSources.class.getDeclaredField("GENERIC").set(null, DamageSource.GENERIC);
DamageSources.class.getDeclaredField("MAGIC").set(null, DamageSource.MAGIC);
DamageSources.class.getDeclaredField("MELTING").set(null, DAMAGESOURCE_MELTING);
DamageSources.class.getDeclaredField("POISON").set(null, DAMAGESOURCE_POISON);
DamageSources.class.getDeclaredField("STARVATION").set(null, DamageSource.STARVE);
DamageSources.class.getDeclaredField("WITHER").set(null, DamageSource.WITHER);
DamageSources.class.getDeclaredField("VOID").set(null, DamageSource.OUT_OF_WORLD);
} catch (Exception e) {
e.printStackTrace();
}
}
use of net.minecraft.util.DamageSource in project SpongeCommon by SpongePowered.
the class DamageEventHandler method createAbsorptionModifier.
public static Optional<DamageFunction> createAbsorptionModifier(EntityLivingBase entityLivingBase, DamageSource damageSource) {
final float absorptionAmount = entityLivingBase.getAbsorptionAmount();
if (absorptionAmount > 0) {
DoubleUnaryOperator function = damage -> -(Math.max(damage - Math.max(damage - absorptionAmount, 0.0F), 0.0F));
// TODO: direct cause creation: bad bad bad
DamageModifier modifier = DamageModifier.builder().cause(Cause.of(EventContext.empty(), entityLivingBase)).type(DamageModifierTypes.ABSORPTION).build();
return Optional.of(new DamageFunction(modifier, function));
}
return Optional.empty();
}
use of net.minecraft.util.DamageSource in project SpongeCommon by SpongePowered.
the class DamageEventHandler method generateCauseFor.
public static void generateCauseFor(DamageSource damageSource) {
if (damageSource instanceof EntityDamageSourceIndirect) {
net.minecraft.entity.Entity source = damageSource.getTrueSource();
if (!(source instanceof EntityPlayer) && source != null) {
final IMixinEntity mixinEntity = EntityUtil.toMixin(source);
mixinEntity.getNotifierUser().ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
mixinEntity.getCreatorUser().ifPresent(owner -> Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner));
}
} else if (damageSource instanceof EntityDamageSource) {
net.minecraft.entity.Entity source = damageSource.getTrueSource();
if (!(source instanceof EntityPlayer) && source != null) {
final IMixinEntity mixinEntity = EntityUtil.toMixin(source);
// TODO only have a UUID, want a user
mixinEntity.getNotifierUser().ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
mixinEntity.getCreatorUser().ifPresent(creator -> Sponge.getCauseStackManager().addContext(EventContextKeys.CREATOR, creator));
}
} else if (damageSource instanceof BlockDamageSource) {
Location<org.spongepowered.api.world.World> location = ((BlockDamageSource) damageSource).getLocation();
BlockPos blockPos = ((IMixinLocation) (Object) location).getBlockPos();
final IMixinChunk mixinChunk = (IMixinChunk) ((net.minecraft.world.World) location.getExtent()).getChunkFromBlockCoords(blockPos);
mixinChunk.getBlockNotifier(blockPos).ifPresent(notifier -> Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier));
mixinChunk.getBlockOwner(blockPos).ifPresent(owner -> Sponge.getCauseStackManager().addContext(EventContextKeys.CREATOR, owner));
}
Sponge.getCauseStackManager().pushCause(damageSource);
}
Aggregations