DialogBodyHandlers.java
net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers
信息
- 全限定名:net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers
- 类型:public class
- 包:net.minecraft.client.gui.screens.dialog.body
- 源码路径:src/main/java/net/minecraft/client/gui/screens/dialog/body/DialogBodyHandlers.java
- 起始行号:L27
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
HANDLERS- 类型:
Map<MapCodec<?extends DialogBody>,DialogBodyHandler<?>> - 修饰符:
private static final - 源码定位:
L29 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers.ItemHandler- 类型:
class - 修饰符:
private static - 源码定位:
L64 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.dialog.body.DialogBodyHandlers.PlainMessageHandler- 类型:
class - 修饰符:
private static - 源码定位:
L109 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
private static <B extends DialogBody> void register(MapCodec<B> type, DialogBodyHandler<?super B> handler) @ L31
- 方法名:register
- 源码定位:L31
- 返回类型: void
- 修饰符:private static
参数:
- type: MapCodec
- handler: DialogBodyHandler<?super B>
说明:
TODO
private static <B extends DialogBody> DialogBodyHandler<B> getHandler(B body) @ L35
- 方法名:getHandler
- 源码定位:L35
- 返回类型: DialogBodyHandler
- 修饰符:private static
参数:
- body: B
说明:
TODO
public static <B extends DialogBody> LayoutElement createBodyElement(DialogScreen<?> screen, B body) @ L39
- 方法名:createBodyElement
- 源码定位:L39
- 返回类型: LayoutElement
- 修饰符:public static
参数:
- screen: DialogScreen<?>
- body: B
说明:
TODO
public static void bootstrap() @ L49
- 方法名:bootstrap
- 源码定位:L49
- 返回类型:void
- 修饰符:public static
参数:
- 无
说明:
TODO
private static void runActionOnParent(DialogScreen<?> parent, Style clickedStyle) @ L54
- 方法名:runActionOnParent
- 源码定位:L54
- 返回类型:void
- 修饰符:private static
参数:
- parent: DialogScreen<?>
- clickedStyle: Style
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class DialogBodyHandlers {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Map<MapCodec<? extends DialogBody>, DialogBodyHandler<?>> HANDLERS = new HashMap<>();
private static <B extends DialogBody> void register(MapCodec<B> type, DialogBodyHandler<? super B> handler) {
HANDLERS.put(type, handler);
}
private static <B extends DialogBody> @Nullable DialogBodyHandler<B> getHandler(B body) {
return (DialogBodyHandler<B>)HANDLERS.get(body.mapCodec());
}
public static <B extends DialogBody> @Nullable LayoutElement createBodyElement(DialogScreen<?> screen, B body) {
DialogBodyHandler<B> handler = getHandler(body);
if (handler == null) {
LOGGER.warn("Unrecognized dialog body {}", body);
return null;
} else {
return handler.createControls(screen, body);
}
}
public static void bootstrap() {
register(PlainMessage.MAP_CODEC, new DialogBodyHandlers.PlainMessageHandler());
register(ItemBody.MAP_CODEC, new DialogBodyHandlers.ItemHandler());
}
private static void runActionOnParent(DialogScreen<?> parent, @Nullable Style clickedStyle) {
if (clickedStyle != null) {
ClickEvent clickEvent = clickedStyle.getClickEvent();
if (clickEvent != null) {
parent.runAction(Optional.of(clickEvent));
}
}
}
@OnlyIn(Dist.CLIENT)
private static class ItemHandler implements DialogBodyHandler<ItemBody> {
public LayoutElement createControls(DialogScreen<?> parent, ItemBody item) {
ItemStack displayStack = item.item().create();
if (item.description().isPresent()) {
PlainMessage description = item.description().get();
LinearLayout layout = LinearLayout.horizontal().spacing(2);
layout.defaultCellSetting().alignVerticallyMiddle();
ItemDisplayWidget itemWidget = new ItemDisplayWidget(
Minecraft.getInstance(),
0,
0,
item.width(),
item.height(),
CommonComponents.EMPTY,
displayStack,
item.showDecorations(),
item.showTooltip()
);
layout.addChild(itemWidget);
layout.addChild(
FocusableTextWidget.builder(description.contents(), parent.getFont())
.maxWidth(description.width())
.alwaysShowBorder(false)
.backgroundFill(FocusableTextWidget.BackgroundFill.NEVER)
.build()
.setComponentClickHandler(style -> DialogBodyHandlers.runActionOnParent(parent, style))
);
return layout;
} else {
return new ItemDisplayWidget(
Minecraft.getInstance(),
0,
0,
item.width(),
item.height(),
displayStack.getHoverName(),
displayStack,
item.showDecorations(),
item.showTooltip()
);
}
}
}
@OnlyIn(Dist.CLIENT)
private static class PlainMessageHandler implements DialogBodyHandler<PlainMessage> {
public LayoutElement createControls(DialogScreen<?> parent, PlainMessage message) {
return FocusableTextWidget.builder(message.contents(), parent.getFont())
.maxWidth(message.width())
.alwaysShowBorder(false)
.backgroundFill(FocusableTextWidget.BackgroundFill.NEVER)
.build()
.setCentered(true)
.setComponentClickHandler(style -> DialogBodyHandlers.runActionOnParent(parent, style));
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Minecraft.getInstance()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FocusableTextWidget.builder()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
ItemDisplayWidget()
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
LinearLayout.horizontal()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/返回值
- 引用位置: