Advertisement
Guest User

FireEventListener

a guest
Jul 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.71 KB | None | 0 0
  1. package com.crowsofwar.avatar.common.bending.fire;
  2.  
  3. import com.crowsofwar.avatar.AvatarInfo;
  4. import com.crowsofwar.avatar.common.AvatarParticles;
  5. import com.crowsofwar.avatar.common.damageutils.AvatarDamageSource;
  6. import com.crowsofwar.avatar.common.data.AbilityData;
  7. import com.crowsofwar.avatar.common.data.Bender;
  8. import com.crowsofwar.avatar.common.data.BendingData;
  9. import com.crowsofwar.avatar.common.entity.EntityShockwave;
  10. import com.crowsofwar.avatar.common.entity.mob.EntityBender;
  11. import com.crowsofwar.avatar.common.util.AvatarUtils;
  12. import com.crowsofwar.gorecore.util.Vector;
  13. import net.minecraft.entity.Entity;
  14. import net.minecraft.entity.EntityLivingBase;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.init.Blocks;
  17. import net.minecraft.init.MobEffects;
  18. import net.minecraft.init.SoundEvents;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.util.DamageSource;
  21. import net.minecraft.util.SoundCategory;
  22. import net.minecraft.util.math.BlockPos;
  23. import net.minecraft.world.World;
  24. import net.minecraft.world.WorldServer;
  25. import net.minecraftforge.event.entity.living.LivingAttackEvent;
  26. import net.minecraftforge.event.entity.living.LivingEvent;
  27. import net.minecraftforge.fml.common.Mod;
  28. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  29.  
  30. import java.util.Objects;
  31.  
  32. import static com.crowsofwar.avatar.common.bending.StatusControl.*;
  33. import static com.crowsofwar.avatar.common.bending.fire.AbilityFireShot.*;
  34. import static com.crowsofwar.avatar.common.config.ConfigStats.STATS_CONFIG;
  35.  
  36. @Mod.EventBusSubscriber(modid = AvatarInfo.MOD_ID)
  37. public class FireEventListener {
  38.     @SubscribeEvent
  39.     public static void onInfernoPunch(LivingAttackEvent event) {
  40.         Entity entity = event.getSource().getTrueSource();
  41.         Entity target = event.getEntity();
  42.         DamageSource source = event.getSource();
  43.         World world = target.getEntityWorld();
  44.         if (entity instanceof EntityLivingBase && !AvatarDamageSource.isAvatarDamageSource(source)) {
  45.             if (event.getSource().getTrueSource() == entity && (entity instanceof EntityBender || entity instanceof EntityPlayer)) {
  46.                 Bender ctx = Bender.get((EntityLivingBase) entity);
  47.                 if (ctx != null) {
  48.                     if (ctx.getInfo().getId() != null) {
  49.                         if (ctx.getData() != null) {
  50.                             Vector direction = Vector.getLookRectangular(entity);
  51.                             AbilityData abilityData = ctx.getData().getAbilityData("inferno_punch");
  52.                             BendingData data = BendingData.get((EntityLivingBase) entity);
  53.                             boolean hasInfernoPunch = data.hasStatusControl(INFERNO_PUNCH_MAIN) || data.hasStatusControl(INFERNO_PUNCH_FIRST);
  54.                             float powerModifier = (float) (ctx.calcPowerRating(Firebending.ID) / 100);
  55.                             float damage = STATS_CONFIG.InfernoPunchDamage + (2 * powerModifier);
  56.                             float knockBack = 1 + powerModifier;
  57.                             int fireTime = 5 + (int) (powerModifier * 10);
  58.  
  59.                             if (abilityData.getLevel() >= 1) {
  60.                                 damage = STATS_CONFIG.InfernoPunchDamage * 4 / 3 + (2 * powerModifier);
  61.                                 knockBack = 1.125F + powerModifier;
  62.                                 fireTime = 6;
  63.                             }
  64.                             if (abilityData.getLevel() >= 2) {
  65.                                 damage = STATS_CONFIG.InfernoPunchDamage * 5 / 3 + (2 * powerModifier);
  66.                                 knockBack = 1.25F + powerModifier;
  67.                                 fireTime = 8 + (int) (powerModifier * 10);
  68.                             }
  69.                             if (data.hasStatusControl(INFERNO_PUNCH_FIRST)) {
  70.                                 damage = STATS_CONFIG.InfernoPunchDamage * 7 / 3 + (2 * powerModifier);
  71.                                 knockBack = 1.5F + powerModifier;
  72.                                 fireTime = 15 + (int) (powerModifier * 10);
  73.                             }
  74.  
  75.                             if (((EntityLivingBase) entity).isPotionActive(MobEffects.STRENGTH)) {
  76.                                 damage += (Objects.requireNonNull(((EntityLivingBase) entity).getActivePotionEffect(MobEffects.STRENGTH)).getAmplifier() + 1) / 2F;
  77.                             }
  78.  
  79.                             if (hasInfernoPunch) {
  80.                                 if (((EntityLivingBase) entity).getHeldItemMainhand() == ItemStack.EMPTY && !(source.getDamageType().startsWith("avatar_"))) {
  81.                                     if (!data.hasStatusControl(INFERNO_PUNCH_SECOND)) {
  82.                                         if (data.hasStatusControl(INFERNO_PUNCH_FIRST)) {
  83.                                             EntityShockwave wave = new EntityShockwave(world);
  84.                                             wave.setPerformanceAmount(15);
  85.                                             wave.setFireTime(15);
  86.                                             wave.setSphere(true);
  87.                                             wave.setParticle(AvatarParticles.getParticleBigFlame());
  88.                                             wave.setParticleSpeed(0.12F);
  89.                                             wave.setParticleAmount(1);
  90.                                             wave.setParticleController(35);
  91.                                             //Used for spheres
  92.                                             wave.setSpeed(0.8F);
  93.                                             wave.setDamageSource(AvatarDamageSource.FIRE);
  94.                                             wave.setParticleAmount(2);
  95.                                             wave.setAbility(new AbilityInfernoPunch());
  96.                                             wave.setDamage(3);
  97.                                             wave.setOwner((EntityLivingBase) entity);
  98.                                             wave.setPosition(target.posX, target.getEntityBoundingBox().minY, target.posZ);
  99.                                             wave.setRange(4);
  100.                                             wave.setKnockbackHeight(0.2);
  101.                                             world.spawnEntity(wave);
  102.                                         }
  103.                                         if (world instanceof WorldServer) {
  104.                                             WorldServer World = (WorldServer) target.getEntityWorld();
  105.                                             for (double angle = 0; angle < 360; angle += 15) {
  106.                                                 Vector pos = Vector.getOrthogonalVector(Vector.getLookRectangular(entity), angle, 0.2);
  107.                                                 World.spawnParticle(world.rand.nextBoolean() ? AvatarParticles.getParticleFlames() : AvatarParticles.getParticleFire(),
  108.                                                         target.posX + pos.x(), (target.posY + (target.getEyeHeight() / 1.25)) + pos.y(), target.posZ + pos.z(),
  109.                                                         4 + abilityData.getLevel(), 0.0, 0.0, 0.0, 0.03 + (abilityData.getLevel() / 100F));
  110.                                             }
  111.                                         }
  112.  
  113.                                         world.playSound(null, target.posX, target.posY, target.posZ, SoundEvents.ENTITY_GHAST_SHOOT,
  114.                                                 SoundCategory.HOSTILE, 4.0F, (1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F);
  115.  
  116.                                         if (target.canBePushed() && target.canBeCollidedWith()) {
  117.                                             DamageSource fire = AvatarDamageSource.causeInfernoPunchDamage(target, entity);
  118.                                             //Creating a new damage source with the attacker as the source results in an infinite loop
  119.                                             target.attackEntityFrom(fire, damage);
  120.                                             target.setFire(fireTime);
  121.                                             target.motionX += direction.x() * knockBack;
  122.                                             target.motionY += direction.y() * knockBack >= 0 ? knockBack / 4 + (direction.y() * knockBack / 4) : knockBack / 4;
  123.                                             target.motionZ += direction.z() * knockBack;
  124.                                             target.isAirBorne = true;
  125.                                             abilityData.addXp(4 - abilityData.getLevel());
  126.                                             // this line is needed to prevent a bug where players will not be pushed in multiplayer
  127.                                             AvatarUtils.afterVelocityAdded(target);
  128.                                         }
  129.                                         ctx.getData().removeStatusControl(INFERNO_PUNCH_FIRST);
  130.                                         ctx.getData().removeStatusControl(INFERNO_PUNCH_MAIN);
  131.                                     }
  132.                                 }
  133.                             }
  134.                         }
  135.                     }
  136.                 }
  137.             }
  138.         }
  139.     }
  140.  
  141.     @SubscribeEvent
  142.     public static void onUpdateEvent(LivingEvent.LivingUpdateEvent event) {
  143.         if (event.getEntityLiving() != null) {
  144.             EntityLivingBase entity = event.getEntityLiving();
  145.             if (entity instanceof EntityPlayer || entity instanceof EntityBender) {
  146.                 Bender b = Bender.get(entity);
  147.                 if (b != null) {
  148.                     if (b.getData().hasBendingId(Firebending.ID)) {
  149.                         if (!ignitedTimes.isEmpty()) {
  150.                             for (BlockPos pos : ignitedTimes.keySet()) {
  151.                                 if (entity.getUniqueID().toString().equals(getIgnitedOwner(pos))) {
  152.                                     ignitedTimes.replace(pos, getIgnitedTimes(pos), getIgnitedTimes(pos) - 1);
  153.                                     if (getIgnitedTimes(pos) == 0) {
  154.                                         if (entity.world.getBlockState(pos).getBlock() == Blocks.FIRE) {
  155.                                             entity.world.setBlockToAir(pos);
  156.                                             ignitedTimes.remove(pos);
  157.                                             ignitedBlocks.remove(pos);
  158.                                         }
  159.                                     }
  160.                                 }
  161.                             }
  162.                         }
  163.                     }
  164.                 }
  165.             }
  166.         }
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement