RecipeToast.java
net.minecraft.client.gui.components.toasts.RecipeToast
信息
- 全限定名:net.minecraft.client.gui.components.toasts.RecipeToast
- 类型:public class
- 包:net.minecraft.client.gui.components.toasts
- 源码路径:src/main/java/net/minecraft/client/gui/components/toasts/RecipeToast.java
- 起始行号:L18
- 实现:Toast
- 职责:
TODO
字段/常量
-
BACKGROUND_SPRITE- 类型:
Identifier - 修饰符:
private static final - 源码定位:
L19 - 说明:
TODO
- 类型:
-
DISPLAY_TIME- 类型:
long - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
TITLE_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
DESCRIPTION_TEXT- 类型:
Component - 修饰符:
private static final - 源码定位:
L22 - 说明:
TODO
- 类型:
-
recipeItems- 类型:
List<RecipeToast.Entry> - 修饰符:
private final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
lastChanged- 类型:
long - 修饰符:
private - 源码定位:
L24 - 说明:
TODO
- 类型:
-
changed- 类型:
boolean - 修饰符:
private - 源码定位:
L25 - 说明:
TODO
- 类型:
-
wantedVisibility- 类型:
Toast.Visibility - 修饰符:
private - 源码定位:
L26 - 说明:
TODO
- 类型:
-
displayedRecipeIndex- 类型:
int - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.client.gui.components.toasts.RecipeToast.Entry- 类型:
record - 修饰符:
private - 源码定位:
L89 - 说明:
TODO
- 类型:
构造器
private RecipeToast() @ L29
- 构造器名:RecipeToast
- 源码定位:L29
- 修饰符:private
参数:
- 无
说明:
TODO
方法
下面的方法块按源码顺序生成。
public Toast.Visibility getWantedVisibility() @ L32
- 方法名:getWantedVisibility
- 源码定位:L32
- 返回类型:Toast.Visibility
- 修饰符:public
参数:
- 无
说明:
TODO
public void update(ToastManager manager, long fullyVisibleForMs) @ L37
- 方法名:update
- 源码定位:L37
- 返回类型:void
- 修饰符:public
参数:
- manager: ToastManager
- fullyVisibleForMs: long
说明:
TODO
public void extractRenderState(GuiGraphicsExtractor graphics, Font font, long fullyVisibleForMs) @ L57
- 方法名:extractRenderState
- 源码定位:L57
- 返回类型:void
- 修饰符:public
参数:
- graphics: GuiGraphicsExtractor
- font: Font
- fullyVisibleForMs: long
说明:
TODO
private void addItem(ItemStack craftingStation, ItemStack unlockedItem) @ L70
- 方法名:addItem
- 源码定位:L70
- 返回类型:void
- 修饰符:private
参数:
- craftingStation: ItemStack
- unlockedItem: ItemStack
说明:
TODO
public static void addOrUpdate(ToastManager toastManager, RecipeDisplay recipe) @ L75
- 方法名:addOrUpdate
- 源码定位:L75
- 返回类型:void
- 修饰符:public static
参数:
- toastManager: ToastManager
- recipe: RecipeDisplay
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class RecipeToast implements Toast {
private static final Identifier BACKGROUND_SPRITE = Identifier.withDefaultNamespace("toast/recipe");
private static final long DISPLAY_TIME = 5000L;
private static final Component TITLE_TEXT = Component.translatable("recipe.toast.title");
private static final Component DESCRIPTION_TEXT = Component.translatable("recipe.toast.description");
private final List<RecipeToast.Entry> recipeItems = new ArrayList<>();
private long lastChanged;
private boolean changed;
private Toast.Visibility wantedVisibility = Toast.Visibility.HIDE;
private int displayedRecipeIndex;
private RecipeToast() {
}
@Override
public Toast.Visibility getWantedVisibility() {
return this.wantedVisibility;
}
@Override
public void update(ToastManager manager, long fullyVisibleForMs) {
if (this.changed) {
this.lastChanged = fullyVisibleForMs;
this.changed = false;
}
if (this.recipeItems.isEmpty()) {
this.wantedVisibility = Toast.Visibility.HIDE;
} else {
this.wantedVisibility = fullyVisibleForMs - this.lastChanged >= 5000.0 * manager.getNotificationDisplayTimeMultiplier()
? Toast.Visibility.HIDE
: Toast.Visibility.SHOW;
}
this.displayedRecipeIndex = (int)(
fullyVisibleForMs / Math.max(1.0, 5000.0 * manager.getNotificationDisplayTimeMultiplier() / this.recipeItems.size()) % this.recipeItems.size()
);
}
@Override
public void extractRenderState(GuiGraphicsExtractor graphics, Font font, long fullyVisibleForMs) {
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, BACKGROUND_SPRITE, 0, 0, this.width(), this.height());
graphics.text(font, TITLE_TEXT, 30, 7, -11534256, false);
graphics.text(font, DESCRIPTION_TEXT, 30, 18, -16777216, false);
RecipeToast.Entry items = this.recipeItems.get(this.displayedRecipeIndex);
graphics.pose().pushMatrix();
graphics.pose().scale(0.6F, 0.6F);
graphics.fakeItem(items.categoryItem(), 3, 3);
graphics.pose().popMatrix();
graphics.fakeItem(items.unlockedItem(), 8, 8);
}
private void addItem(ItemStack craftingStation, ItemStack unlockedItem) {
this.recipeItems.add(new RecipeToast.Entry(craftingStation, unlockedItem));
this.changed = true;
}
public static void addOrUpdate(ToastManager toastManager, RecipeDisplay recipe) {
RecipeToast toast = toastManager.getToast(RecipeToast.class, NO_TOKEN);
if (toast == null) {
toast = new RecipeToast();
toastManager.addToast(toast);
}
ContextMap context = SlotDisplayContext.fromLevel(toastManager.getMinecraft().level);
ItemStack categoryItem = recipe.craftingStation().resolveForFirstStack(context);
ItemStack unlockedItem = recipe.result().resolveForFirstStack(context);
toast.addItem(categoryItem, unlockedItem);
}
@OnlyIn(Dist.CLIENT)
private record Entry(ItemStack categoryItem, ItemStack unlockedItem) {
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/实现/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Component.translatable()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Identifier.withDefaultNamespace()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SlotDisplayContext.fromLevel()
- 引用位置: