Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.rendering.v1.level.sky;

import org.jetbrains.annotations.ApiStatus;

@ApiStatus.NonExtendable
public interface CelestialRenderContext extends SkyRenderContext {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs docs.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do sometime soon

Type type();

enum Type {
SUN,
MOON,
STARS
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.rendering.v1.level.sky;

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.client.renderer.SkyRenderer;
import net.minecraft.client.renderer.state.level.SkyRenderState;

@ApiStatus.NonExtendable
public interface SkyRenderContext {
SkyRenderer skyRenderer();

SkyRenderState skyRenderState();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.api.client.rendering.v1.level.sky;

import net.minecraft.resources.Identifier;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;

/**
* To be used when adding custom skies or to modify existing aspects of the skys rendering.
*/
public final class SkyRenderEvents {
private SkyRenderEvents() {
}

/**
* Called at the start of the "addSkyPass" lambda.
*/
public static final Event<PreSky> PRE_SKY = EventFactory.createArrayBacked(PreSky.class, callbacks -> context -> {
for (final PreSky callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called at the end of the "addSkyPass" lambda.
*/
public static final Event<PostSky> POST_SKY = EventFactory.createArrayBacked(PostSky.class, callbacks -> context -> {
for (final PostSky callback : callbacks) {
callback.execute(context);
}
});

/**
* Called before "renderEndSky" is invoked, determines if the end sky should render or not.
*/
public static final Event<PreEndSky> PRE_END_SKY = EventFactory.createArrayBacked(PreEndSky.class, callbacks -> context -> {
for (final PreEndSky callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called after "renderEndSky" is invoked.
*/
public static final Event<PostEndSky> POST_END_SKY = EventFactory.createArrayBacked(PostEndSky.class, callbacks -> context -> {
for (final PostEndSky callback : callbacks) {
callback.execute(context);
}
});

/**
* Called before "renderEndFlash" is invoked, determines if the end flash should render or not.
*/
public static final Event<PreEndFlash> PRE_END_FLASH = EventFactory.createArrayBacked(PreEndFlash.class, callbacks -> context -> {
for (final PreEndFlash callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called after "renderEndFlash" is invoked.
*/
public static final Event<PostEndFlash> POST_END_FLASH = EventFactory.createArrayBacked(PostEndFlash.class, callbacks -> context -> {
for (final PostEndFlash callback : callbacks) {
callback.execute(context);
}
});

/**
* Called before the top/bottom sky disc is rendered, determines if it should render or not.
*/
public static final Event<PreSkyDisc> PRE_SKY_DISC = EventFactory.createArrayBacked(PreSkyDisc.class, callbacks -> context -> {
for (final PreSkyDisc callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called after the top/bottom sky disc is rendered.
*/
public static final Event<PostSkyDisc> POST_SKY_DISC = EventFactory.createArrayBacked(PostSkyDisc.class, callbacks -> context -> {
for (final PostSkyDisc callback : callbacks) {
callback.execute(context);
}
});

/**
* Called when sunrise/sunset in the Overworld is rendered.
*/
public static final Event<PreSunriseSunset> PRE_SUNRISE_SUNSET = EventFactory.createArrayBacked(PreSunriseSunset.class, callbacks -> context -> {
for (final PreSunriseSunset callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called when sunrise/sunset in the Overworld is rendered.
*/
public static final Event<PostSunriseSunset> POST_SUNRISE_SUNSET = EventFactory.createArrayBacked(PostSunriseSunset.class, callbacks -> context -> {
for (final PostSunriseSunset callback : callbacks) {
callback.execute(context);
}
});

/**
* Called after the rendering of the sun/moon/stars.
*/
public static final Event<PostSunMoonStars> POST_SUN_MOON_STARS = EventFactory.createArrayBacked(PostSunMoonStars.class, callbacks -> context -> {
for (final PostSunMoonStars callback : callbacks) {
callback.execute(context);
}
});

/**
* Called before the sun, moon, or stars are rendered.
*/
public static final Event<PreCelestial> PRE_CELESTIAL = EventFactory.createArrayBacked(PreCelestial.class, callbacks -> context -> {
for (final PreCelestial callback : callbacks) {
if (callback.execute(context)) {
return true;
}
}

return false;
});

/**
* Called after the sun, moon, or stars are rendered.
*/
public static final Event<PostCelestial> POST_CELESTIAL = EventFactory.createArrayBacked(PostCelestial.class, callbacks -> context -> {
for (final PostCelestial callback : callbacks) {
callback.execute(context);
}
});

/**
* Unused by FAPI, intended for mod developers to invoke when adding custom elements to the sky when rendering allowing other mods to intercept them and do as please.
*/
public static final Event<PreCustomElement> PRE_CUSTOM_ELEMENT = EventFactory.createArrayBacked(PreCustomElement.class, callbacks -> (key, context) -> {
for (final PreCustomElement callback : callbacks) {
if (callback.execute(key, context)) {
return true;
}
}

return false;
});

/**
* Unused by FAPI, intended for mod developers to invoke when adding custom elements to the sky when rendering allowing other mods to intercept them and do as please.
*/
public static final Event<PostCustomElement> POST_CUSTOM_ELEMENT = EventFactory.createArrayBacked(PostCustomElement.class, callbacks -> (key, context) -> {
for (final PostCustomElement callback : callbacks) {
callback.execute(key, context);
}
});

@FunctionalInterface
public interface PreSky {
boolean execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostSky {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PreEndSky {
boolean execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostEndSky {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PreEndFlash {
boolean execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostEndFlash {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PreSkyDisc {
boolean execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostSkyDisc {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PreSunriseSunset {
boolean execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostSunriseSunset {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PostSunMoonStars {
void execute(SkyRenderContext context);
}

@FunctionalInterface
public interface PreCelestial {
boolean execute(CelestialRenderContext context);
}

@FunctionalInterface
public interface PostCelestial {
void execute(CelestialRenderContext context);
}

@FunctionalInterface
public interface PreCustomElement {
boolean execute(Identifier key, Object context);
}

@FunctionalInterface
public interface PostCustomElement {
void execute(Identifier key, Object context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.impl.client.rendering.level.sky;

import net.minecraft.client.renderer.SkyRenderer;
import net.minecraft.client.renderer.state.level.SkyRenderState;

import net.fabricmc.fabric.api.client.rendering.v1.level.sky.CelestialRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.level.sky.SkyRenderContext;

public class SkyRenderContextImpl implements SkyRenderContext {
private SkyRenderer skyRenderer;
private SkyRenderState skyRenderState;

public void prepare(final SkyRenderer skyRenderer, final SkyRenderState skyRenderState) {
this.skyRenderer = skyRenderer;
this.skyRenderState = skyRenderState;
}

@Override
public SkyRenderer skyRenderer() {
return this.skyRenderer;
}

@Override
public SkyRenderState skyRenderState() {
return this.skyRenderState;
}

public static class CelestialContextImpl extends SkyRenderContextImpl implements CelestialRenderContext {
private Type type;

public void setType(final Type type) {
this.type = type;
}

@Override
public Type type() {
return this.type;
}
}
}
Loading
Loading