LegacyHoverEventFix.java
net.minecraft.util.datafix.fixes.LegacyHoverEventFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.LegacyHoverEventFix
- 类型:public class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/LegacyHoverEventFix.java
- 起始行号:L21
- 继承:DataFix
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
public LegacyHoverEventFix(Schema outputSchema) @ L22
- 构造器名:LegacyHoverEventFix
- 源码定位:L22
- 修饰符:public
参数:
- outputSchema: Schema
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected TypeRewriteRule makeRule() @ L26
- 方法名:makeRule
- 源码定位:L26
- 返回类型:TypeRewriteRule
- 修饰符:protected
参数:
- 无
说明:
TODO
private <C,H extends Pair<String,?>> TypeRewriteRule createFixer(Type<C> rawTextComponentType, Type<H> hoverEventType) @ L34
- 方法名:createFixer
- 源码定位:L34
- 返回类型:<C,H extends Pair<String,?>> TypeRewriteRule
- 修饰符:private
参数:
- rawTextComponentType: Type
- hoverEventType: Type
说明:
TODO
private <H> H fixHoverEvent(Type<H> hoverEventType, String action, Dynamic<?> oldHoverEvent) @ L79
- 方法名:fixHoverEvent
- 源码定位:L79
- 返回类型:
H - 修饰符:private
参数:
- hoverEventType: Type
- action: String
- oldHoverEvent: Dynamic<?>
说明:
TODO
private static <H> H fixShowTextHover(Type<H> hoverEventType, Dynamic<?> oldHoverEvent) @ L83
- 方法名:fixShowTextHover
- 源码定位:L83
- 返回类型:
H - 修饰符:private static
参数:
- hoverEventType: Type
- oldHoverEvent: Dynamic<?>
说明:
TODO
private static <H> H createPlaceholderHover(Type<H> hoverEventType, Dynamic<?> oldHoverEvent) @ L88
- 方法名:createPlaceholderHover
- 源码定位:L88
- 返回类型:
H - 修饰符:private static
参数:
- hoverEventType: Type
- oldHoverEvent: Dynamic<?>
说明:
TODO
代码
public class LegacyHoverEventFix extends DataFix {
public LegacyHoverEventFix(Schema outputSchema) {
super(outputSchema, false);
}
@Override
protected TypeRewriteRule makeRule() {
Type<? extends Pair<String, ?>> hoverEventType = (Type<? extends Pair<String, ?>>)this.getInputSchema()
.getType(References.TEXT_COMPONENT)
.findFieldType("hoverEvent");
return this.createFixer(this.getInputSchema().getTypeRaw(References.TEXT_COMPONENT), hoverEventType);
}
private <C, H extends Pair<String, ?>> TypeRewriteRule createFixer(Type<C> rawTextComponentType, Type<H> hoverEventType) {
Type<Pair<String, Either<Either<String, List<C>>, Pair<Either<List<C>, Unit>, Pair<Either<C, Unit>, Pair<Either<H, Unit>, Dynamic<?>>>>>>> textComponentType = DSL.named(
References.TEXT_COMPONENT.typeName(),
DSL.or(
DSL.or(DSL.string(), DSL.list(rawTextComponentType)),
DSL.and(
DSL.optional(DSL.field("extra", DSL.list(rawTextComponentType))),
DSL.optional(DSL.field("separator", rawTextComponentType)),
DSL.optional(DSL.field("hoverEvent", hoverEventType)),
DSL.remainderType()
)
)
);
if (!textComponentType.equals(this.getInputSchema().getType(References.TEXT_COMPONENT))) {
throw new IllegalStateException(
"Text component type did not match, expected " + textComponentType + " but got " + this.getInputSchema().getType(References.TEXT_COMPONENT)
);
} else {
return this.fixTypeEverywhere(
"LegacyHoverEventFix",
textComponentType,
ops -> named -> named.mapSecond(
simpleOrFull -> simpleOrFull.mapRight(
full -> full.mapSecond(separatorHoverRemainder -> separatorHoverRemainder.mapSecond(hoverAndRemainder -> {
Dynamic<?> remainder = hoverAndRemainder.getSecond();
Optional<? extends Dynamic<?>> hoverEvent = remainder.get("hoverEvent").result();
if (hoverEvent.isEmpty()) {
return hoverAndRemainder;
} else {
Optional<? extends Dynamic<?>> legacyHoverValue = hoverEvent.get().get("value").result();
if (legacyHoverValue.isEmpty()) {
return hoverAndRemainder;
} else {
String hoverAction = hoverAndRemainder.getFirst().left().map(Pair::getFirst).orElse("");
H newHoverEvent = this.fixHoverEvent(hoverEventType, hoverAction, (Dynamic<?>)hoverEvent.get());
return hoverAndRemainder.mapFirst(ignored -> Either.left(newHoverEvent));
}
}
}))
)
)
);
}
}
private <H> H fixHoverEvent(Type<H> hoverEventType, String action, Dynamic<?> oldHoverEvent) {
return "show_text".equals(action) ? fixShowTextHover(hoverEventType, oldHoverEvent) : createPlaceholderHover(hoverEventType, oldHoverEvent);
}
private static <H> H fixShowTextHover(Type<H> hoverEventType, Dynamic<?> oldHoverEvent) {
Dynamic<?> newHoverEvent = oldHoverEvent.renameField("value", "contents");
return Util.readTypedOrThrow(hoverEventType, newHoverEvent).getValue();
}
private static <H> H createPlaceholderHover(Type<H> hoverEventType, Dynamic<?> oldHoverEvent) {
JsonElement oldJson = oldHoverEvent.convert(JsonOps.INSTANCE).getValue();
Dynamic<?> placeholderHoverEvent = new Dynamic<>(
JavaOps.INSTANCE,
Map.of("action", "show_text", "contents", Map.<String, String>of("text", "Legacy hoverEvent: " + GsonHelper.toStableString(oldJson)))
);
return Util.readTypedOrThrow(hoverEventType, placeholderHoverEvent).getValue();
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
GsonHelper.toStableString()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.readTypedOrThrow()
- 引用位置:
-
- 引用位置:
参数
- 引用位置: