HoverEvent.java
net.minecraft.network.chat.HoverEvent
信息
- 全限定名:net.minecraft.network.chat.HoverEvent
- 类型:public interface
- 包:net.minecraft.network.chat
- 源码路径:src/main/java/net/minecraft/network/chat/HoverEvent.java
- 起始行号:L19
- 职责:
TODO
字段/常量
CODEC- 类型:
Codec<HoverEvent> - 修饰符:
package-private - 源码定位:
L20 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.network.chat.HoverEvent.Action- 类型:
enum - 修饰符:
public static - 源码定位:
L24 - 说明:
TODO
- 类型:
-
net.minecraft.network.chat.HoverEvent.EntityTooltipInfo- 类型:
class - 修饰符:
public static - 源码定位:
L60 - 说明:
TODO
- 类型:
-
net.minecraft.network.chat.HoverEvent.ShowEntity- 类型:
record - 修饰符:
public - 源码定位:
L115 - 说明:
TODO
- 类型:
-
net.minecraft.network.chat.HoverEvent.ShowItem- 类型:
record - 修饰符:
public - 源码定位:
L126 - 说明:
TODO
- 类型:
-
net.minecraft.network.chat.HoverEvent.ShowText- 类型:
record - 修饰符:
public - 源码定位:
L135 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
HoverEvent.Action action() @ L22
- 方法名:action
- 源码定位:L22
- 返回类型:HoverEvent.Action
- 修饰符:package-private
参数:
- 无
说明:
TODO
代码
public interface HoverEvent {
Codec<HoverEvent> CODEC = HoverEvent.Action.CODEC.dispatch("action", HoverEvent::action, action -> action.codec);
HoverEvent.Action action();
public static enum Action implements StringRepresentable {
SHOW_TEXT("show_text", true, HoverEvent.ShowText.CODEC),
SHOW_ITEM("show_item", true, HoverEvent.ShowItem.CODEC),
SHOW_ENTITY("show_entity", true, HoverEvent.ShowEntity.CODEC);
public static final Codec<HoverEvent.Action> UNSAFE_CODEC = StringRepresentable.fromValues(HoverEvent.Action::values);
public static final Codec<HoverEvent.Action> CODEC = UNSAFE_CODEC.validate(HoverEvent.Action::filterForSerialization);
private final String name;
private final boolean allowFromServer;
private final MapCodec<? extends HoverEvent> codec;
private Action(String name, boolean allowFromServer, MapCodec<? extends HoverEvent> codec) {
this.name = name;
this.allowFromServer = allowFromServer;
this.codec = codec;
}
public boolean isAllowedFromServer() {
return this.allowFromServer;
}
@Override
public String getSerializedName() {
return this.name;
}
@Override
public String toString() {
return "<action " + this.name + ">";
}
private static DataResult<HoverEvent.Action> filterForSerialization(HoverEvent.Action action) {
return !action.isAllowedFromServer() ? DataResult.error(() -> "Action not allowed: " + action) : DataResult.success(action, Lifecycle.stable());
}
}
public static class EntityTooltipInfo {
public static final MapCodec<HoverEvent.EntityTooltipInfo> CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(
BuiltInRegistries.ENTITY_TYPE.byNameCodec().fieldOf("id").forGetter(o -> o.type),
UUIDUtil.LENIENT_CODEC.fieldOf("uuid").forGetter(o -> o.uuid),
ComponentSerialization.CODEC.optionalFieldOf("name").forGetter(o -> o.name)
)
.apply(i, HoverEvent.EntityTooltipInfo::new)
);
public final EntityType<?> type;
public final UUID uuid;
public final Optional<Component> name;
private @Nullable List<Component> linesCache;
public EntityTooltipInfo(EntityType<?> type, UUID uuid, @Nullable Component name) {
this(type, uuid, Optional.ofNullable(name));
}
public EntityTooltipInfo(EntityType<?> type, UUID uuid, Optional<Component> name) {
this.type = type;
this.uuid = uuid;
this.name = name;
}
public List<Component> getTooltipLines() {
if (this.linesCache == null) {
this.linesCache = new ArrayList<>();
this.name.ifPresent(this.linesCache::add);
this.linesCache.add(Component.translatable("gui.entity_tooltip.type", this.type.getDescription()));
this.linesCache.add(Component.literal(this.uuid.toString()));
}
return this.linesCache;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o != null && this.getClass() == o.getClass()) {
HoverEvent.EntityTooltipInfo that = (HoverEvent.EntityTooltipInfo)o;
return this.type.equals(that.type) && this.uuid.equals(that.uuid) && this.name.equals(that.name);
} else {
return false;
}
}
@Override
public int hashCode() {
int result = this.type.hashCode();
result = 31 * result + this.uuid.hashCode();
return 31 * result + this.name.hashCode();
}
}
public record ShowEntity(HoverEvent.EntityTooltipInfo entity) implements HoverEvent {
public static final MapCodec<HoverEvent.ShowEntity> CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(HoverEvent.EntityTooltipInfo.CODEC.forGetter(HoverEvent.ShowEntity::entity)).apply(i, HoverEvent.ShowEntity::new)
);
@Override
public HoverEvent.Action action() {
return HoverEvent.Action.SHOW_ENTITY;
}
}
public record ShowItem(ItemStackTemplate item) implements HoverEvent {
public static final MapCodec<HoverEvent.ShowItem> CODEC = ItemStackTemplate.MAP_CODEC.xmap(HoverEvent.ShowItem::new, HoverEvent.ShowItem::item);
@Override
public HoverEvent.Action action() {
return HoverEvent.Action.SHOW_ITEM;
}
}
public record ShowText(Component value) implements HoverEvent {
public static final MapCodec<HoverEvent.ShowText> CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(ComponentSerialization.CODEC.fieldOf("value").forGetter(HoverEvent.ShowText::value)).apply(i, HoverEvent.ShowText::new)
);
@Override
public HoverEvent.Action action() {
return HoverEvent.Action.SHOW_TEXT;
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
Component.literal(), Component.translatable()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringRepresentable.fromValues()
- 引用位置: