-
Notifications
You must be signed in to change notification settings - Fork 523
Add Advancement Renderers #5132
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cda94e2
Add advancement renderers
8s2 50429ef
Fix import ordering
8s2 c1d93f6
Move context classes into inner classes
8s2 d327bf1
Add missing renderer javadocs
8s2 cf1f231
Rename accessor methods
8s2 576b441
Remove accesswidener
8s2 e626505
Fix renderer registration check and exceptions
8s2 1f43277
Use named locals for args
8s2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...fabricmc/fabric/api/client/rendering/v1/advancement/AbstractAdvancementRenderContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import net.minecraft.advancements.Advancement; | ||
| import net.minecraft.advancements.AdvancementHolder; | ||
| import net.minecraft.advancements.AdvancementProgress; | ||
| import net.minecraft.advancements.DisplayInfo; | ||
| import net.minecraft.client.gui.GuiGraphics; | ||
|
|
||
| @ApiStatus.NonExtendable | ||
| public interface AbstractAdvancementRenderContext { | ||
| /** | ||
| * The graphics instance used for rendering. | ||
| * @return {@link GuiGraphics} instance | ||
| */ | ||
| GuiGraphics graphics(); | ||
|
|
||
| /** | ||
| * The holder for the advancement. | ||
| * @return {@link AdvancementHolder} instance | ||
| */ | ||
| AdvancementHolder holder(); | ||
|
|
||
| /** | ||
| * @return The advancement's progress, or {@code null} if there is no progress. | ||
| */ | ||
| @Nullable | ||
| AdvancementProgress progress(); | ||
|
|
||
| default Advancement advancement() { | ||
| return holder().value(); | ||
| } | ||
|
|
||
| default DisplayInfo display() { | ||
| return advancement().display().orElseThrow(); | ||
| } | ||
|
|
||
| /** | ||
| * @return {@code true} if the advancement has been obtained. | ||
| */ | ||
| default boolean isObtained() { | ||
| AdvancementProgress progress = progress(); | ||
| return progress != null && progress.getPercent() >= 1; | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
...bricmc/fabric/api/client/rendering/v1/advancement/AdvancementBackgroundRenderContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| import net.minecraft.client.gui.navigation.ScreenRectangle; | ||
|
|
||
| @ApiStatus.NonExtendable | ||
| public interface AdvancementBackgroundRenderContext extends AbstractAdvancementRenderContext { | ||
8s2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * @return the {@link ScreenRectangle} that the background is contained within. | ||
| * @apiNote use {@link ScreenRectangle#left()} and {@link ScreenRectangle#top()} for the starting coordinates of the background. | ||
| */ | ||
| ScreenRectangle bounds(); | ||
|
|
||
| /** | ||
| * @return the background's x scroll offset. | ||
| */ | ||
| double scrollX(); | ||
|
|
||
| /** | ||
| * @return the background's y scroll offset. | ||
| */ | ||
| double scrollY(); | ||
| } | ||
37 changes: 37 additions & 0 deletions
37
...et/fabricmc/fabric/api/client/rendering/v1/advancement/AdvancementFrameRenderContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| @ApiStatus.NonExtendable | ||
| public interface AdvancementFrameRenderContext extends AbstractAdvancementRenderContext { | ||
| /** | ||
| * @return The x coordinate of the frame's top-left corner. | ||
| */ | ||
| int x(); | ||
|
|
||
| /** | ||
| * @return The y coordinate of the frame's top-left corner. | ||
| */ | ||
| int y(); | ||
|
|
||
| /** | ||
| * @return {@code true} if the mouse is hovered over the frame. | ||
| */ | ||
| boolean isHovered(); | ||
| } |
42 changes: 42 additions & 0 deletions
42
...net/fabricmc/fabric/api/client/rendering/v1/advancement/AdvancementIconRenderContext.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| @ApiStatus.NonExtendable | ||
| public interface AdvancementIconRenderContext extends AbstractAdvancementRenderContext { | ||
| /** | ||
| * @return The x coordinate of the icon's top-left corner. | ||
| */ | ||
| int x(); | ||
|
|
||
| /** | ||
| * @return The y coordinate of the icon's top-left corner. | ||
| */ | ||
| int y(); | ||
|
|
||
| /** | ||
| * @return {@code true} if the mouse is hovered over the icon. | ||
| */ | ||
| boolean isHovered(); | ||
|
|
||
| /** | ||
| * @return {@code true} if the icon is rendered as a selected tab. | ||
| */ | ||
| boolean isSelected(); | ||
| } |
109 changes: 109 additions & 0 deletions
109
...ent/java/net/fabricmc/fabric/api/client/rendering/v1/advancement/AdvancementRenderer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import net.minecraft.resources.Identifier; | ||
|
|
||
| import net.fabricmc.fabric.impl.client.rendering.advancement.AdvancementRendererRegistryImpl; | ||
|
|
||
| /** | ||
| * Advancement renderers allow for custom advancement icons, frames, and backgrounds | ||
| * which render in the {@link net.minecraft.client.gui.screens.advancements.AdvancementsScreen advancements screen} | ||
| * and {@link net.minecraft.client.gui.components.toasts.AdvancementToast advancement toasts}. | ||
| */ | ||
| public final class AdvancementRenderer { | ||
| /** | ||
| * Registers an {@link IconRenderer} for advancement icons that show on advancement widgets, tabs, and toasts. | ||
| * @param iconRenderer the icon renderer | ||
| * @param advancementIds identifiers of the advancements | ||
| * @throws IllegalArgumentException if an advancement already has a registered icon renderer | ||
| * @throws NullPointerException if either an advancement id or the icon renderer is null | ||
| */ | ||
| public static void registerIcon(IconRenderer iconRenderer, Identifier... advancementIds) { | ||
| AdvancementRendererRegistryImpl.registerIcon(iconRenderer, advancementIds); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a {@link FrameRenderer} for advancement frames that show on advancement widgets. | ||
| * @param frameRenderer the frame renderer | ||
| * @param advancementIds identifiers of the advancements | ||
| * @throws IllegalArgumentException if an advancement already has a registered frame renderer | ||
| * @throws NullPointerException if either an advancement id or the frame renderer is null | ||
| */ | ||
| public static void registerFrame(FrameRenderer frameRenderer, Identifier... advancementIds) { | ||
| AdvancementRendererRegistryImpl.registerFrame(frameRenderer, advancementIds); | ||
| } | ||
|
|
||
| /** | ||
| * Registers a {@link BackgroundRenderer} for the backgrounds of advancement tabs. | ||
| * | ||
| * <p>Only root advancements render their backgrounds. | ||
| * @param backgroundRenderer the frame renderer | ||
| * @param advancementIds identifiers of the advancements | ||
| * @throws IllegalArgumentException if an advancement already has a registered background renderer | ||
| * @throws NullPointerException if either an advancement id or the background renderer is null | ||
| */ | ||
| public static void registerBackground(BackgroundRenderer backgroundRenderer, Identifier... advancementIds) { | ||
| AdvancementRendererRegistryImpl.registerBackground(backgroundRenderer, advancementIds); | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| public interface IconRenderer { | ||
| void renderAdvancementIcon(AdvancementIconRenderContext context); | ||
|
|
||
| /** | ||
| * @return {@code true} if the original advancement icon should render alongside this icon renderer. | ||
| */ | ||
| default boolean shouldRenderOriginalIcon() { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| public interface FrameRenderer { | ||
| void renderAdvancementFrame(AdvancementFrameRenderContext context); | ||
|
|
||
| /** | ||
| * @return {@code true} if the original advancement frame should render alongside this frame renderer. | ||
| */ | ||
| default boolean shouldRenderOriginalFrame() { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * @return {@code true} if the tooltip of a hovered advancement widget should render. | ||
| */ | ||
| default boolean shouldRenderTooltip() { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| public interface BackgroundRenderer { | ||
| void renderAdvancementBackground(AdvancementBackgroundRenderContext context); | ||
|
|
||
| /** | ||
| * @return {@code true} if the original advancement background should render alongside this background renderer. | ||
| */ | ||
| default boolean shouldRenderOriginalBackground() { | ||
| return false; | ||
| } | ||
| } | ||
8s2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private AdvancementRenderer() { | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
...icmc/fabric/impl/client/rendering/advancement/AdvancementBackgroundRenderContextImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.impl.client.rendering.advancement; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import net.minecraft.advancements.AdvancementHolder; | ||
| import net.minecraft.advancements.AdvancementProgress; | ||
| import net.minecraft.client.gui.GuiGraphics; | ||
| import net.minecraft.client.gui.navigation.ScreenRectangle; | ||
|
|
||
| import net.fabricmc.fabric.api.client.rendering.v1.advancement.AdvancementBackgroundRenderContext; | ||
|
|
||
| public record AdvancementBackgroundRenderContextImpl(GuiGraphics graphics, AdvancementHolder holder, @Nullable AdvancementProgress progress, ScreenRectangle bounds, double scrollX, double scrollY) implements AdvancementBackgroundRenderContext { | ||
8s2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
28 changes: 28 additions & 0 deletions
28
.../fabricmc/fabric/impl/client/rendering/advancement/AdvancementFrameRenderContextImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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.advancement; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import net.minecraft.advancements.AdvancementHolder; | ||
| import net.minecraft.advancements.AdvancementProgress; | ||
| import net.minecraft.client.gui.GuiGraphics; | ||
|
|
||
| import net.fabricmc.fabric.api.client.rendering.v1.advancement.AdvancementFrameRenderContext; | ||
|
|
||
| public record AdvancementFrameRenderContextImpl(GuiGraphics graphics, AdvancementHolder holder, @Nullable AdvancementProgress progress, int x, int y, boolean isHovered) implements AdvancementFrameRenderContext { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.