示例#1
0
 public void func_28002_e() {
   try {
     field_28006_b = new byte[0];
     renderGlobal.func_28137_f();
   } catch (Throwable throwable) {
   }
   try {
     System.gc();
     AxisAlignedBB.func_28196_a();
     Vec3D.func_28215_a();
   } catch (Throwable throwable1) {
   }
   try {
     System.gc();
     changeWorld1(null);
   } catch (Throwable throwable2) {
   }
   System.gc();
 }
  protected void updatePlayerActionState() {
    if (riddenByEntity != null && tamed) {
      return;
    }
    hasAttacked = false;
    float f = 16F;
    if (playerToAttack == null) {
      playerToAttack = findPlayerToAttack();
      if (playerToAttack != null && EntityHelper.getInWater(playerToAttack)) {
        a = worldObj.getPathToEntity(this, playerToAttack, f);
      }
    } else if (!playerToAttack.isEntityAlive() || !EntityHelper.getInWater(playerToAttack)) {
      playerToAttack = null;
    } else {
      float f1 = playerToAttack.getDistanceToEntity(this);
      if (canEntityBeSeen(playerToAttack)) {
        attackEntity(playerToAttack, f1);
      }
    }
    if (!hasAttacked
        && playerToAttack != null
        && EntityHelper.getInWater(playerToAttack)
        && (a == null || rand.nextInt(20) == 0)) {
      a = worldObj.getPathToEntity(this, playerToAttack, f);
    } else if (a == null && rand.nextInt(80) == 0 || rand.nextInt(80) == 0) {
      boolean flag = false;
      int j = -1;
      int k = -1;
      int l = -1;
      float f2 = -99999F;
      for (int i1 = 0; i1 < 10; i1++) {
        int j1 = MathHelper.floor_double((posX + (double) rand.nextInt(13)) - 6D);
        int k1 = MathHelper.floor_double((posY + (double) rand.nextInt(7)) - 3D);
        int l1 = MathHelper.floor_double((posZ + (double) rand.nextInt(13)) - 6D);
        float f3 = getBlockPathWeight(j1, k1, l1);
        if (f3 > f2) {
          f2 = f3;
          j = j1;
          k = k1;
          l = l1;
          flag = true;
        }
      }

      if (flag) {
        a = worldObj.getEntityPathToXYZ(this, j, k, l, 10F);
      }
    }
    int i = MathHelper.floor_double(boundingBox.minY);
    boolean flag1 = handleWaterMovement();
    boolean flag2 = handleLavaMovement();
    rotationPitch = 0.0F;
    if (a == null || rand.nextInt(100) == 0) {
      super.updatePlayerActionState();
      a = null;
      return;
    }
    Vec3D vec3d = a.getPosition(this);
    for (double d = width * 2.0F;
        vec3d != null && vec3d.squareDistanceTo(posX, vec3d.yCoord, posZ) < d * d; ) {
      a.incrementPathIndex();
      if (a.isFinished()) {
        vec3d = null;
        a = null;
      } else {
        vec3d = a.getPosition(this);
      }
    }

    isJumping = false;
    if (vec3d != null) {
      double d1 = vec3d.xCoord - posX;
      double d2 = vec3d.zCoord - posZ;
      double d3 = vec3d.yCoord - (double) i;
      float f4 = (float) ((Math.atan2(d2, d1) * 180D) / 3.1415927410125728D) - 90F;
      float f5 = f4 - rotationYaw;
      moveForward = moveSpeed;
      for (; f5 < -180F; f5 += 360F) {}
      for (; f5 >= 180F; f5 -= 360F) {}
      if (f5 > 30F) {
        f5 = 30F;
      }
      if (f5 < -30F) {
        f5 = -30F;
      }
      rotationYaw += f5;
      if (hasAttacked && playerToAttack != null) {
        double d4 = playerToAttack.posX - posX;
        double d5 = playerToAttack.posZ - posZ;
        float f6 = rotationYaw;
        rotationYaw = (float) ((Math.atan2(d5, d4) * 180D) / 3.1415927410125728D) - 90F;
        float f7 = (((f6 - rotationYaw) + 90F) * 3.141593F) / 180F;
        moveStrafing = -MathHelper.sin(f7) * moveForward * 1.0F;
        moveForward = MathHelper.cos(f7) * moveForward * 1.0F;
      }
      if (d3 > 0.0D && playerToAttack != null && EntityHelper.getInWater(playerToAttack)) {
        isJumping = true;
      }
    }
    if (playerToAttack != null) {
      faceEntity(playerToAttack, 30F, 30F);
    }
    if (isCollidedHorizontally) {
      isJumping = true;
    }
    if (rand.nextFloat() < 0.8F && (flag1 || flag2)) {
      isJumping = true;
    }
  }
  /** Called to update the entity's position/logic. */
  public void onUpdate() {
    lastTickPosX = posX;
    lastTickPosY = posY;
    lastTickPosZ = posZ;
    super.onUpdate();

    if (throwableShake > 0) {
      throwableShake--;
    }

    if (inGround) {
      int i = worldObj.getBlockId(xTile, yTile, zTile);

      if (i != inTile) {
        inGround = false;
        motionX *= rand.nextFloat() * 0.2F;
        motionY *= rand.nextFloat() * 0.2F;
        motionZ *= rand.nextFloat() * 0.2F;
        ticksInGround = 0;
        ticksInAir = 0;
      } else {
        ticksInGround++;

        if (ticksInGround == 1200) {
          setDead();
        }

        return;
      }
    } else {
      ticksInAir++;
    }

    Vec3D vec3d = Vec3D.createVector(posX, posY, posZ);
    Vec3D vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);
    MovingObjectPosition movingobjectposition = worldObj.rayTraceBlocks(vec3d, vec3d1);
    vec3d = Vec3D.createVector(posX, posY, posZ);
    vec3d1 = Vec3D.createVector(posX + motionX, posY + motionY, posZ + motionZ);

    if (movingobjectposition != null) {
      vec3d1 =
          Vec3D.createVector(
              movingobjectposition.hitVec.xCoord,
              movingobjectposition.hitVec.yCoord,
              movingobjectposition.hitVec.zCoord);
    }

    if (!worldObj.isRemote) {
      Entity entity = null;
      List list =
          worldObj.getEntitiesWithinAABBExcludingEntity(
              this, boundingBox.addCoord(motionX, motionY, motionZ).expand(1.0D, 1.0D, 1.0D));
      double d = 0.0D;

      for (int k = 0; k < list.size(); k++) {
        Entity entity1 = (Entity) list.get(k);

        if (!entity1.canBeCollidedWith() || entity1 == thrower && ticksInAir < 5) {
          continue;
        }

        float f4 = 0.3F;
        AxisAlignedBB axisalignedbb = entity1.boundingBox.expand(f4, f4, f4);
        MovingObjectPosition movingobjectposition1 =
            axisalignedbb.calculateIntercept(vec3d, vec3d1);

        if (movingobjectposition1 == null) {
          continue;
        }

        double d1 = vec3d.distanceTo(movingobjectposition1.hitVec);

        if (d1 < d || d == 0.0D) {
          entity = entity1;
          d = d1;
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }
    }

    if (movingobjectposition != null) {
      onImpact(movingobjectposition);
    }

    posX += motionX;
    posY += motionY;
    posZ += motionZ;
    float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
    rotationYaw = (float) ((Math.atan2(motionX, motionZ) * 180D) / Math.PI);

    for (rotationPitch = (float) ((Math.atan2(motionY, f) * 180D) / Math.PI);
        rotationPitch - prevRotationPitch < -180F;
        prevRotationPitch -= 360F) {}

    for (; rotationPitch - prevRotationPitch >= 180F; prevRotationPitch += 360F) {}

    for (; rotationYaw - prevRotationYaw < -180F; prevRotationYaw -= 360F) {}

    for (; rotationYaw - prevRotationYaw >= 180F; prevRotationYaw += 360F) {}

    rotationPitch = prevRotationPitch + (rotationPitch - prevRotationPitch) * 0.2F;
    rotationYaw = prevRotationYaw + (rotationYaw - prevRotationYaw) * 0.2F;
    float f1 = 0.99F;
    float f2 = func_40075_e();

    if (isInWater()) {
      for (int j = 0; j < 4; j++) {
        float f3 = 0.25F;
        worldObj.spawnParticle(
            "bubble",
            posX - motionX * (double) f3,
            posY - motionY * (double) f3,
            posZ - motionZ * (double) f3,
            motionX,
            motionY,
            motionZ);
      }

      f1 = 0.8F;
    }

    motionX *= f1;
    motionY *= f1;
    motionZ *= f1;
    motionY -= f2;
    setPosition(posX, posY, posZ);
  }
示例#4
0
  public void run() {
    running = true;
    try {
      startGame();
    } catch (Exception exception) {
      exception.printStackTrace();
      onMinecraftCrash(new UnexpectedThrowable("Failed to start game", exception));
      return;
    }
    try {
      long l = System.currentTimeMillis();
      int i = 0;
      do {
        if (!running) {
          break;
        }
        try {
          if (mcApplet != null && !mcApplet.isActive()) {
            break;
          }
          AxisAlignedBB.clearBoundingBoxPool();
          Vec3D.initialize();
          if (mcCanvas == null && Display.isCloseRequested()) {
            shutdown();
          }
          if (isGamePaused && theWorld != null) {
            float f = timer.renderPartialTicks;
            timer.updateTimer();
            timer.renderPartialTicks = f;
          } else {
            timer.updateTimer();
          }
          long l1 = System.nanoTime();
          for (int j = 0; j < timer.elapsedTicks; j++) {
            ticksRan++;
            try {
              runTick();
              continue;
            } catch (MinecraftException minecraftexception1) {
              theWorld = null;
            }
            changeWorld1(null);
            displayGuiScreen(new GuiConflictWarning());
          }

          long l2 = System.nanoTime() - l1;
          checkGLError("Pre render");
          RenderBlocks.fancyGrass = gameSettings.fancyGraphics;
          sndManager.func_338_a(thePlayer, timer.renderPartialTicks);
          GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
          if (theWorld != null) {
            theWorld.updatingLighting();
          }
          if (!Keyboard.isKeyDown(65)) {
            Display.update();
          }
          if (thePlayer != null && thePlayer.isEntityInsideOpaqueBlock()) {
            gameSettings.thirdPersonView = false;
          }
          if (!skipRenderWorld) {
            if (playerController != null) {
              playerController.setPartialTime(timer.renderPartialTicks);
            }
            entityRenderer.updateCameraAndRender(timer.renderPartialTicks);
          }
          if (!Display.isActive()) {
            if (fullscreen) {
              toggleFullscreen();
            }
            Thread.sleep(10L);
          }
          if (gameSettings.showDebugInfo) {
            displayDebugInfo(l2);
          } else {
            prevFrameTime = System.nanoTime();
          }
          guiAchievement.updateAchievementWindow();
          Thread.yield();
          if (Keyboard.isKeyDown(65)) {
            Display.update();
          }
          screenshotListener();
          if (mcCanvas != null
              && !fullscreen
              && (mcCanvas.getWidth() != displayWidth || mcCanvas.getHeight() != displayHeight)) {
            displayWidth = mcCanvas.getWidth();
            displayHeight = mcCanvas.getHeight();
            if (displayWidth <= 0) {
              displayWidth = 1;
            }
            if (displayHeight <= 0) {
              displayHeight = 1;
            }
            resize(displayWidth, displayHeight);
          }
          checkGLError("Post render");
          i++;
          isGamePaused =
              !isMultiplayerWorld() && currentScreen != null && currentScreen.doesGuiPauseGame();
          while (System.currentTimeMillis() >= l + 1000L) {
            debug =
                (new StringBuilder())
                    .append(i)
                    .append(" fps, ")
                    .append(WorldRenderer.chunksUpdated)
                    .append(" chunk updates")
                    .toString();
            WorldRenderer.chunksUpdated = 0;
            l += 1000L;
            i = 0;
          }
        } catch (MinecraftException minecraftexception) {
          theWorld = null;
          changeWorld1(null);
          displayGuiScreen(new GuiConflictWarning());
        } catch (OutOfMemoryError outofmemoryerror) {
          func_28002_e();
          displayGuiScreen(new GuiErrorScreen());
          System.gc();
        }
      } while (true);
    } catch (MinecraftError minecrafterror) {
    } catch (Throwable throwable) {
      func_28002_e();
      throwable.printStackTrace();
      onMinecraftCrash(new UnexpectedThrowable("Unexpected error", throwable));
    } finally {
      shutdownMinecraftApplet();
    }
  }