Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions fabric-rendering-v1/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version = getSubprojectVersion(project)

loom {
accessWidenerPath = file("src/client/resources/fabric-rendering-v1.accesswidener")
}

moduleDependencies(project, [
':fabric-api-base',
':fabric-transitive-access-wideners-v1',
Expand Down
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;
}
}
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 {
/**
* @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();
}
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();
}
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();
}
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;
}
}

private AdvancementRenderer() {
}
}
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 {
}
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 {
}
Loading
Loading