use of net.minecraftforge.event.entity.living.LivingAttackEvent in project MatterOverdrive-Community-Edition-1.12.2 by Matter-Overdrive-Community-Edition.
the class BioticStatShield method onLivingEvent.
@SubscribeEvent(priority = EventPriority.HIGH)
public void onLivingEvent(AndroidPlayer androidPlayer, int level, LivingEvent event) {
if (event instanceof LivingAttackEvent) {
DamageSource source = ((LivingAttackEvent) event).getSource();
if (getShieldState(androidPlayer)) {
int energyReqired = MathHelper.ceil(((LivingAttackEvent) event).getAmount() * ENERGY_PER_DAMAGE);
if (isDamageValid(source) && event.isCancelable()) {
if (source.getTrueSource() != null) {
// NBTTagCompound attack = new NBTTagCompound();
// NBTTagList attackList = androidPlayer.getEffectTagList(AndroidPlayer.NBT_HITS, 10);
// attack.setDouble("x", source.getSourceOfDamage().posX - event.entityLiving.posX);
// attack.setDouble("y", source.getSourceOfDamage().posY - (event.entityLiving.posY + 1.5));
// attack.setDouble("z", source.getSourceOfDamage().posZ - event.entityLiving.posZ);
// attack.setInteger("time", 10);
// attackList.appendTag(attack);
// androidPlayer.setEffectsTag(AndroidPlayer.NBT_HITS, attackList);
// androidPlayer.sync(EnumSet.of(AndroidPlayer.DataType.EFFECTS),true);
androidPlayer.getPlayer().world.playSound(null, androidPlayer.getPlayer().posX, androidPlayer.getPlayer().posY, androidPlayer.getPlayer().posZ, MatterOverdriveSounds.androidShieldHit, SoundCategory.PLAYERS, 0.5f, 0.9f + random.nextFloat() * 0.2f);
}
if (androidPlayer.hasEnoughEnergyScaled(energyReqired)) {
androidPlayer.extractEnergyScaled(energyReqired);
event.setResult(Event.Result.DENY);
event.setCanceled(true);
}
}
}
} else if (event instanceof LivingHurtEvent) {
DamageSource source = ((LivingHurtEvent) event).getSource();
if (getShieldState(androidPlayer)) {
int energyReqired = MathHelper.ceil(((LivingHurtEvent) event).getAmount() * ENERGY_PER_DAMAGE);
if (isDamageValid(source)) {
double energyMultiply = androidPlayer.getPlayer().getAttributeMap().getAttributeInstance(AndroidAttributes.attributeBatteryUse).getAttributeValue();
energyReqired *= energyMultiply;
int energyExtracted = androidPlayer.extractEnergy(energyReqired, true);
event.setResult(Event.Result.DENY);
event.setCanceled(true);
} else {
((LivingHurtEvent) event).setAmount(0F);
event.setResult(Event.Result.DENY);
event.setCanceled(true);
}
}
}
}
use of net.minecraftforge.event.entity.living.LivingAttackEvent in project MatterOverdrive-Community-Edition-1.12.2 by Matter-Overdrive-Community-Edition.
the class BioticStatAutoShield method onLivingEvent.
@SubscribeEvent(priority = EventPriority.HIGH)
public void onLivingEvent(AndroidPlayer androidPlayer, int level, LivingEvent event) {
if (event instanceof LivingAttackEvent) {
DamageSource source = ((LivingAttackEvent) event).getSource();
if (!OverdriveBioticStats.shield.getShieldState(androidPlayer)) {
if (OverdriveBioticStats.shield.isDamageValid(source) && event.isCancelable() && OverdriveBioticStats.shield.canActivate(androidPlayer)) {
event.setResult(Event.Result.DENY);
event.setCanceled(true);
OverdriveBioticStats.shield.setShield(androidPlayer, true);
}
}
} else if (event instanceof LivingHurtEvent) {
DamageSource source = ((LivingHurtEvent) event).getSource();
if (!OverdriveBioticStats.shield.getShieldState(androidPlayer)) {
if (OverdriveBioticStats.shield.isDamageValid(source) && event.isCancelable() && OverdriveBioticStats.shield.canActivate(androidPlayer)) {
((LivingHurtEvent) event).setAmount(0F);
event.setResult(Event.Result.DENY);
event.setCanceled(true);
OverdriveBioticStats.shield.setShield(androidPlayer, true);
}
}
}
}
Aggregations