Ejemplo n.º 1
0
 public static void addTile(TileEntityLight light) {
   ILightRenderHandler handler = light.getRenderHandler();
   if (handler != null && handler.rendersLight()) {
     ClientProxy.lights.add(light);
   }
 }
Ejemplo n.º 2
0
  @Override
  public int compare(TileEntityLight arg1, TileEntityLight arg2) {
    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
    if (player == null) {
      return 0;
    }

    ILightRenderHandler handler1 = arg1.getRenderHandler();
    ILightRenderHandler handler2 = arg2.getRenderHandler();

    if (handler1.rendersLight() && !handler2.rendersLight()) {
      return -1;
    } else if (!handler1.rendersLight() && handler2.rendersLight()) {
      return 1;
    }

    if (handler1.rendersFirst() && !handler2.rendersFirst()) {
      return -1;
    } else if (!handler1.rendersFirst() && handler2.rendersFirst()) {
      return 1;
    }

    AxisAlignedBB aabb1 = handler1.getRenderingAABB(arg1, 1.0F);
    AxisAlignedBB aabb2 = handler2.getRenderingAABB(arg2, 1.0F);

    double offsetX1 = (aabb1.maxX - aabb1.minX) / 2.0D;
    double offsetY1 = (aabb1.maxY - aabb1.minY) / 2.0D;
    double offsetZ1 = (aabb1.maxZ - aabb1.minZ) / 2.0D;
    double offsetX2 = (aabb2.maxX - aabb2.minX) / 2.0D;
    double offsetY2 = (aabb2.maxY - aabb2.minY) / 2.0D;
    double offsetZ2 = (aabb2.maxZ - aabb2.minZ) / 2.0D;

    double distX1 = arg1.xCoord - player.posX;
    double distY1 = arg1.yCoord - player.posY;
    double distZ1 = arg1.zCoord - player.posZ;
    double distX2 = arg2.xCoord - player.posX;
    double distY2 = arg2.yCoord - player.posY;
    double distZ2 = arg2.zCoord - player.posZ;

    //      double dist1 = distX1 * distX1 + distY1 * distY1 + distZ1 * distZ1;
    //      double dist2 = distX2 * distX2 + distY2 * distY2 + distZ2 * distZ2;
    //
    //      if (dist1 < dist2) {
    //          return 1;
    //      }
    //      else if (dist1 > dist2) {
    //          return -1;
    //      }
    //      else {
    //          return 0;
    //      }

    double distOffX1 = distX1 + offsetX1;
    double distOffY1 = distY1 + offsetY1;
    double distOffZ1 = distZ1 + offsetZ1;
    double distOffX2 = distX2 + offsetX2;
    double distOffY2 = distY2 + offsetY2;
    double distOffZ2 = distZ2 + offsetZ2;

    double distOff1 = distOffX1 * distOffX1 + distOffY1 * distOffY1 + distOffZ1 * distOffZ1;
    double distOff2 = distOffX2 * distOffX2 + distOffY2 * distOffY2 + distOffZ2 * distOffZ2;

    if (distOff1 < distOff2) {
      return 1;
    } else if (distOff1 > distOff2) {
      return -1;
    } else {
      return 0;
    }
  }
Ejemplo n.º 3
0
  @SubscribeEvent
  public void onRenderWorldLast(RenderWorldLastEvent event) {
    MC.getMinecraft().mcProfiler.startSection("discotek");
    this.totalCount = 0;
    this.renderedCount = 0;
    if (ClientProxy.lights.isEmpty()) {
      MC.getMinecraft().mcProfiler.endSection();
      return;
    }
    MC.getMinecraft().mcProfiler.startSection("invalidation");
    Iterator<TileEntityLight> iterator = ClientProxy.lights.iterator();

    while (iterator.hasNext()) {
      TileEntityLight light = iterator.next();

      if (light.isNotValid()) {
        iterator.remove();
      }
    }

    if (ClientProxy.lights.isEmpty()) {
      MC.getMinecraft().mcProfiler.endSection();
      MC.getMinecraft().mcProfiler.endSection();
      return;
    }

    MC.getMinecraft().mcProfiler.endStartSection("sorting");

    ClientProxy.reusableLights.addAll(ClientProxy.lights);

    MC.getMinecraft().mcProfiler.endStartSection("culling");

    EntityClientPlayerMP player = MC.getMinecraft().thePlayer;

    double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.partialTicks;
    double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.partialTicks;
    double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.partialTicks;

    Frustrum frustrum = new Frustrum();
    frustrum.setPosition(playerX, playerY, playerZ);

    iterator = ClientProxy.reusableLights.iterator();

    while (iterator.hasNext()) {
      this.totalCount++;

      TileEntityLight light = iterator.next();

      ILightRenderHandler handler = light.getRenderHandler();

      if (handler != null) {
        AxisAlignedBB aabb =
            handler
                .getRenderingAABB(light, event.partialTicks)
                .offset(light.xCoord, light.yCoord, light.zCoord);

        if (!frustrum.isBoundingBoxInFrustum(aabb)) {
          // iterator.remove();
          continue;
        }
      } else {
        iterator.remove();
        continue;
      }

      this.renderedCount++;
    }

    MC.getMinecraft().mcProfiler.endStartSection("rendering");

    TileEntityLightRenderer.lightOnly = true;

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    // MC.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    // GL11.glPolygonOffset(-3.0F, -3.0F);
    GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    iterator = ClientProxy.reusableLights.iterator();

    while (iterator.hasNext()) {
      GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
      TileEntityLight light = iterator.next();
      double d3 = light.xCoord - playerX;
      double d4 = light.yCoord - playerY;
      double d5 = light.zCoord - playerZ;

      if (light.isNotValid()) {
        iterator.remove();
      }

      if (d3 * d3 + d4 * d4 + d5 * d5 < 65536.0D) {
        TileEntityRendererDispatcher.instance.renderTileEntityAt(
            light, d3, d4, d5, event.partialTicks);
      }
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    // GL11.glPolygonOffset(0.0F, 0.0F);
    GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glDepthMask(true);
    GL11.glPopMatrix();

    TileEntityLightRenderer.lightOnly = false;
    ClientProxy.reusableLights.clear();

    MC.getMinecraft().mcProfiler.endSection();
    MC.getMinecraft().mcProfiler.endSection();
  }