Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add render sky event #3611

Open
wants to merge 1 commit into
base: 1.20.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ private WorldRenderEvents() { }
}
});

/**
* Called when rendering the world's skybox.
* This happens right before terrain setup.
*
* <p>Use this for rendering custom sky boxes in existing dimensions,
* such as rendering more stars above a current y value.
*
* <p>Returning false will cancel rendering the skybox. This has no
* effect on other subscribers to this event - all subscribers will always be called.
*/
public static final Event<RenderSky> RENDER_SKY = EventFactory.createArrayBacked(RenderSky.class, (context, fogCallback) -> true, callbacks -> (context, fogCallback) -> {
boolean shouldRender = true;

for (final RenderSky callback : callbacks) {
if (!callback.renderSky(context, fogCallback)) {
shouldRender = false;
}
}

return shouldRender;
});

/**
* Called after all framebuffer writes are complete but before all world
* rendering is torn down.
Expand Down Expand Up @@ -302,6 +324,11 @@ public interface AfterTranslucent {
void afterTranslucent(WorldRenderContext context);
}

@FunctionalInterface
public interface RenderSky {
boolean renderSky(WorldRenderContext context, Runnable fogCallback);
}

@FunctionalInterface
public interface Last {
void onLast(WorldRenderContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,11 @@ private void renderSky(MatrixStack matrices, Matrix4f matrix4f, float tickDelta,
}
}
}

@Inject(method = "renderSky(Lnet/minecraft/client/util/math/MatrixStack;Lorg/joml/Matrix4f;FLnet/minecraft/client/render/Camera;ZLjava/lang/Runnable;)V", at = @At("HEAD"), cancellable = true)
private void onRenderSky(MatrixStack matrices, Matrix4f projectionMatrix, float tickDelta, Camera camera, boolean thickFog, Runnable fogCallback, CallbackInfo info) {
if (!WorldRenderEvents.RENDER_SKY.invoker().renderSky(context, fogCallback)) {
info.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.OverlayTexture;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

Expand Down Expand Up @@ -48,9 +50,16 @@ private static boolean onBlockOutline(WorldRenderContext wrc, WorldRenderContext
return true;
}

private static boolean onRenderSky(WorldRenderContext wrc, Runnable fogCallback) {
ClientPlayerEntity player = MinecraftClient.getInstance().player;

return !player.isHolding(Items.DEBUG_STICK) || !(player.getY() > 200);
}

// Renders a diamond block above diamond blocks when they are looked at.
@Override
public void onInitializeClient() {
WorldRenderEvents.BLOCK_OUTLINE.register(WorldRenderEventsTests::onBlockOutline);
WorldRenderEvents.RENDER_SKY.register(WorldRenderEventsTests::onRenderSky);
}
}
Loading