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
  @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();
  }