Advertisement
GamingLVScripts

onEntityUpdate

Apr 1st, 2024
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.33 KB | None | 0 0
  1. /**
  2.      * Gets called every tick from main Entity class
  3.      */
  4.     public void onEntityUpdate()
  5.     {
  6.         this.prevSwingProgress = this.swingProgress;
  7.         super.onEntityUpdate();
  8.         this.worldObj.theProfiler.startSection("livingEntityBaseTick");
  9.         boolean flag = this instanceof EntityPlayer;
  10.  
  11.         if (this.isEntityAlive())
  12.         {
  13.             if (this.isEntityInsideOpaqueBlock())
  14.             {
  15.                 this.attackEntityFrom(DamageSource.inWall, 1.0F);
  16.             }
  17.             else if (flag && !this.worldObj.getWorldBorder().contains(this.getEntityBoundingBox()))
  18.             {
  19.                 double d0 = this.worldObj.getWorldBorder().getClosestDistance(this) + this.worldObj.getWorldBorder().getDamageBuffer();
  20.  
  21.                 if (d0 < 0.0D)
  22.                 {
  23.                     this.attackEntityFrom(DamageSource.inWall, (float)Math.max(1, MathHelper.floor_double(-d0 * this.worldObj.getWorldBorder().getDamageAmount())));
  24.                 }
  25.             }
  26.         }
  27.  
  28.         if (this.isImmuneToFire() || this.worldObj.isRemote)
  29.         {
  30.             this.extinguish();
  31.         }
  32.  
  33.         boolean flag1 = flag && ((EntityPlayer)this).capabilities.disableDamage;
  34.  
  35.         if (this.isEntityAlive())
  36.         {
  37.             if (this.isInsideOfMaterial(Material.water))
  38.             {
  39.                 if (!this.canBreatheUnderwater() && !this.isPotionActive(Potion.waterBreathing.id) && !flag1)
  40.                 {
  41.                     this.setAir(this.decreaseAirSupply(this.getAir()));
  42.  
  43.                     if (this.getAir() == -20)
  44.                     {
  45.                         this.setAir(0);
  46.  
  47.                         for (int i = 0; i < 8; ++i)
  48.                         {
  49.                             float f = this.rand.nextFloat() - this.rand.nextFloat();
  50.                             float f1 = this.rand.nextFloat() - this.rand.nextFloat();
  51.                             float f2 = this.rand.nextFloat() - this.rand.nextFloat();
  52.                             this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + (double)f, this.posY + (double)f1, this.posZ + (double)f2, this.motionX, this.motionY, this.motionZ, new int[0]);
  53.                         }
  54.  
  55.                         this.attackEntityFrom(DamageSource.drown, 2.0F);
  56.                     }
  57.                 }
  58.  
  59.                 if (!this.worldObj.isRemote && this.isRiding() && this.ridingEntity instanceof EntityLivingBase)
  60.                 {
  61.                     this.mountEntity((Entity)null);
  62.                 }
  63.             }
  64.             else
  65.             {
  66.                 this.setAir(300);
  67.             }
  68.         }
  69.  
  70.         if (this.isEntityAlive() && this.isWet())
  71.         {
  72.             this.extinguish();
  73.         }
  74.  
  75.         this.prevCameraPitch = this.cameraPitch;
  76.  
  77.         if (this.hurtTime > 0)
  78.         {
  79.             --this.hurtTime;
  80.         }
  81.  
  82.         if (this.hurtResistantTime > 0 && !(this instanceof EntityPlayerMP))
  83.         {
  84.             --this.hurtResistantTime;
  85.         }
  86.  
  87.         if (this.getHealth() <= 0.0F)
  88.         {
  89.             this.onDeathUpdate();
  90.         }
  91.  
  92.         if (this.recentlyHit > 0)
  93.         {
  94.             --this.recentlyHit;
  95.         }
  96.         else
  97.         {
  98.             this.attackingPlayer = null;
  99.         }
  100.  
  101.         if (this.lastAttacker != null && !this.lastAttacker.isEntityAlive())
  102.         {
  103.             this.lastAttacker = null;
  104.         }
  105.  
  106.         if (this.entityLivingToAttack != null)
  107.         {
  108.             if (!this.entityLivingToAttack.isEntityAlive())
  109.             {
  110.                 this.setRevengeTarget((EntityLivingBase)null);
  111.             }
  112.             else if (this.ticksExisted - this.revengeTimer > 100)
  113.             {
  114.                 this.setRevengeTarget((EntityLivingBase)null);
  115.             }
  116.         }
  117.  
  118.         this.updatePotionEffects();
  119.         this.prevMovedDistance = this.movedDistance;
  120.         this.prevRenderYawOffset = this.renderYawOffset;
  121.         this.prevRotationYawHead = this.rotationYawHead;
  122.         this.prevRotationYaw = this.rotationYaw;
  123.         this.prevRotationPitch = this.rotationPitch;
  124.         if(this == Minecraft.getMinecraft().thePlayer) {
  125.             this.prevRotationYawHead = PlayerHandler.yaw;
  126.             PlayerHandler.prevPitch = PlayerHandler.pitch;
  127.         }
  128.         this.worldObj.theProfiler.endSection();
  129.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement