Advertisement
GamingLVScripts

onLivingUpdate

Apr 1st, 2024
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.94 KB | None | 0 0
  1. /**
  2.      * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons
  3.      * use this to react to sunlight and start to burn.
  4.      */
  5.     public void onLivingUpdate()
  6.     {
  7.         if (this.sprintingTicksLeft > 0)
  8.         {
  9.             --this.sprintingTicksLeft;
  10.  
  11.             if (this.sprintingTicksLeft == 0)
  12.             {
  13.                 this.setSprinting(false);
  14.             }
  15.         }
  16.  
  17.         if (this.sprintToggleTimer > 0)
  18.         {
  19.             --this.sprintToggleTimer;
  20.         }
  21.  
  22.         this.prevTimeInPortal = this.timeInPortal;
  23.  
  24.         if (this.inPortal)
  25.         {
  26.             if (this.mc.currentScreen != null && !this.mc.currentScreen.doesGuiPauseGame())
  27.             {
  28.                 this.mc.displayGuiScreen((GuiScreen)null);
  29.             }
  30.  
  31.             if (this.timeInPortal == 0.0F)
  32.             {
  33.                 this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.rand.nextFloat() * 0.4F + 0.8F));
  34.             }
  35.  
  36.             this.timeInPortal += 0.0125F;
  37.  
  38.             if (this.timeInPortal >= 1.0F)
  39.             {
  40.                 this.timeInPortal = 1.0F;
  41.             }
  42.  
  43.             this.inPortal = false;
  44.         }
  45.         else if (this.isPotionActive(Potion.confusion) && this.getActivePotionEffect(Potion.confusion).getDuration() > 60)
  46.         {
  47.             this.timeInPortal += 0.006666667F;
  48.  
  49.             if (this.timeInPortal > 1.0F)
  50.             {
  51.                 this.timeInPortal = 1.0F;
  52.             }
  53.         }
  54.         else
  55.         {
  56.             if (this.timeInPortal > 0.0F)
  57.             {
  58.                 this.timeInPortal -= 0.05F;
  59.             }
  60.  
  61.             if (this.timeInPortal < 0.0F)
  62.             {
  63.                 this.timeInPortal = 0.0F;
  64.             }
  65.         }
  66.  
  67.         if (this.timeUntilPortal > 0)
  68.         {
  69.             --this.timeUntilPortal;
  70.         }
  71.  
  72.         boolean flag = this.movementInput.jump;
  73.         boolean flag1 = this.movementInput.sneak;
  74.         float f = 0.8F;
  75.         boolean flag2 = this.movementInput.moveForward >= f;
  76.         final boolean flag3 = this.movementInput.moveForward >= f;
  77.         final float forward = this.movementInput.moveForward;
  78.         final float strafe = this.movementInput.moveStrafe;
  79.         this.movementInput.updatePlayerMoveState();
  80.         new SilentMoveEvent().publishItself();
  81.         if (PlayerHandler.moveFix && PlayerHandler.currentMode == PlayerHandler.MoveFixMode.SILENT) {
  82.             final float[] floats = this.mySilentStrafe(this.movementInput.moveStrafe, this.movementInput.moveForward, this.rotationYaw, true);
  83.             final float diffForward = forward - floats[1];
  84.             final float diffStrafe = strafe - floats[0];
  85.             if (this.movementInput.sneak) {
  86.                 this.movementInput.moveStrafe = MathHelper.clamp_float(floats[0], -0.3f, 0.3f);
  87.                 this.movementInput.moveForward = MathHelper.clamp_float(floats[1], -0.3f, 0.3f);
  88.             }
  89.             else {
  90.                 if (diffForward >= 2.0f) {
  91.                     floats[1] = 0.0f;
  92.                 }
  93.                 if (diffForward <= -2.0f) {
  94.                     floats[1] = 0.0f;
  95.                 }
  96.                 if (diffStrafe >= 2.0f) {
  97.                     floats[0] = 0.0f;
  98.                 }
  99.                 if (diffStrafe <= -2.0f) {
  100.                     floats[0] = 0.0f;
  101.                 }
  102.                 this.movementInput.moveStrafe = MathHelper.clamp_float(floats[0], -1.0f, 1.0f);
  103.                 this.movementInput.moveForward = MathHelper.clamp_float(floats[1], -1.0f, 1.0f);
  104.             }
  105.         }
  106.  
  107.         NoSlowEvent noSlowEvent = new NoSlowEvent(0.2f, 0.2f);
  108.         noSlowEvent.publishItself();
  109.  
  110.         if (this.isUsingItem() && !this.isRiding())
  111.         {
  112.             MovementInput moveInput1 = this.movementInput;
  113.             moveInput1.moveStrafe *= noSlowEvent.getStrafe();
  114.             MovementInput moveInput2 = this.movementInput;
  115.             moveInput2.moveForward *= noSlowEvent.getForward();
  116.             this.sprintToggleTimer = 0;
  117.         }
  118.  
  119.         this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
  120.         this.pushOutOfBlocks(this.posX - (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
  121.         this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ - (double)this.width * 0.35D);
  122.         this.pushOutOfBlocks(this.posX + (double)this.width * 0.35D, this.getEntityBoundingBox().minY + 0.5D, this.posZ + (double)this.width * 0.35D);
  123.         boolean flag69 = (float) this.getFoodStats().getFoodLevel() > 6.0F || this.capabilities.allowFlying;
  124.  
  125.         float movef = this.movementInput.moveForward;
  126.         if (PlayerHandler.shouldSprintReset) {
  127.             movef = this.movementInput.moveForward;
  128.             this.movementInput.moveForward = 0;
  129.         }
  130.         if (this.onGround && !flag1 && !flag2 && this.movementInput.moveForward >= f && !this.isSprinting() && flag69 && (!this.isUsingItem() || noSlowEvent.isSprint()) && !this.isPotionActive(Potion.blindness)) {
  131.             if (this.sprintToggleTimer <= 0 && !this.mc.gameSettings.keyBindSprint.isKeyDown()) {
  132.                 this.sprintToggleTimer = 7;
  133.             } else {
  134.                 this.setSprinting(true);
  135.             }
  136.         }
  137.  
  138.         if (!this.isSprinting() && this.movementInput.moveForward >= f && flag69 && (!this.isUsingItem() || noSlowEvent.isSprint()) && !this.isPotionActive(Potion.blindness) && this.mc.gameSettings.keyBindSprint.isKeyDown()) {
  139.             this.setSprinting(true);
  140.         }
  141.  
  142.         final DirectionSprintCheckEvent sprintCheckEvent = new DirectionSprintCheckEvent(this.movementInput.moveForward < f).publishItself();
  143.         if (this.isSprinting() && (sprintCheckEvent.isSprintCheck() || this.isCollidedHorizontally || !flag69)) {
  144.             this.setSprinting(false);
  145.         }
  146.  
  147.         if (!noSlowEvent.isSprint() && this.isUsingItem() && !this.isRiding()) {
  148.             this.setSprinting(false);
  149.         }
  150.  
  151.         if (PlayerHandler.shouldSprintReset) {
  152.             this.movementInput.moveForward = movef;
  153.             PlayerHandler.shouldSprintReset = false;
  154.         }
  155.  
  156.         if (this.capabilities.allowFlying)
  157.         {
  158.             if (this.mc.playerController.isSpectatorMode())
  159.             {
  160.                 if (!this.capabilities.isFlying)
  161.                 {
  162.                     this.capabilities.isFlying = true;
  163.                     this.sendPlayerAbilities();
  164.                 }
  165.             }
  166.             else if (!flag && this.movementInput.jump)
  167.             {
  168.                 if (this.flyToggleTimer == 0)
  169.                 {
  170.                     this.flyToggleTimer = 7;
  171.                 }
  172.                 else
  173.                 {
  174.                     this.capabilities.isFlying = !this.capabilities.isFlying;
  175.                     this.sendPlayerAbilities();
  176.                     this.flyToggleTimer = 0;
  177.                 }
  178.             }
  179.         }
  180.  
  181.         if (this.capabilities.isFlying && this.isCurrentViewEntity())
  182.         {
  183.             if (this.movementInput.sneak)
  184.             {
  185.                 this.motionY -= (double)(this.capabilities.getFlySpeed() * 3.0F);
  186.             }
  187.  
  188.             if (this.movementInput.jump)
  189.             {
  190.                 this.motionY += (double)(this.capabilities.getFlySpeed() * 3.0F);
  191.             }
  192.         }
  193.  
  194.         if (this.isRidingHorse())
  195.         {
  196.             if (this.horseJumpPowerCounter < 0)
  197.             {
  198.                 ++this.horseJumpPowerCounter;
  199.  
  200.                 if (this.horseJumpPowerCounter == 0)
  201.                 {
  202.                     this.horseJumpPower = 0.0F;
  203.                 }
  204.             }
  205.  
  206.             if (flag && !this.movementInput.jump)
  207.             {
  208.                 this.horseJumpPowerCounter = -10;
  209.                 this.sendHorseJump();
  210.             }
  211.             else if (!flag && this.movementInput.jump)
  212.             {
  213.                 this.horseJumpPowerCounter = 0;
  214.                 this.horseJumpPower = 0.0F;
  215.             }
  216.             else if (flag)
  217.             {
  218.                 ++this.horseJumpPowerCounter;
  219.  
  220.                 if (this.horseJumpPowerCounter < 10)
  221.                 {
  222.                     this.horseJumpPower = (float)this.horseJumpPowerCounter * 0.1F;
  223.                 }
  224.                 else
  225.                 {
  226.                     this.horseJumpPower = 0.8F + 2.0F / (float)(this.horseJumpPowerCounter - 9) * 0.1F;
  227.                 }
  228.             }
  229.         }
  230.         else
  231.         {
  232.             this.horseJumpPower = 0.0F;
  233.         }
  234.  
  235.         super.onLivingUpdate();
  236.  
  237.         if (this.onGround && this.capabilities.isFlying && !this.mc.playerController.isSpectatorMode())
  238.         {
  239.             this.capabilities.isFlying = false;
  240.             this.sendPlayerAbilities();
  241.         }
  242.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement