EntityRenameFix.java
net.minecraft.util.datafix.fixes.EntityRenameFix
信息
- 全限定名:net.minecraft.util.datafix.fixes.EntityRenameFix
- 类型:public abstract class
- 包:net.minecraft.util.datafix.fixes
- 源码路径:src/main/java/net/minecraft/util/datafix/fixes/EntityRenameFix.java
- 起始行号:L16
- 继承:DataFix
- 职责:
TODO
字段/常量
name- 类型:
String - 修饰符:
protected final - 源码定位:
L17 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public EntityRenameFix(String name, Schema outputSchema, boolean changesType) @ L19
- 构造器名:EntityRenameFix
- 源码定位:L19
- 修饰符:public
参数:
- name: String
- outputSchema: Schema
- changesType: boolean
说明:
TODO
方法
下面的方法块按源码顺序生成。
public TypeRewriteRule makeRule() @ L24
- 方法名:makeRule
- 源码定位:L24
- 返回类型:TypeRewriteRule
- 修饰符:public
参数:
- 无
说明:
TODO
private <A> Typed<A> getEntity(Object input, DynamicOps<?> ops, Type<A> oldEntityType) @ L52
- 方法名:getEntity
- 源码定位:L52
- 返回类型: Typed
- 修饰符:private
参数:
说明:
TODO
protected abstract Pair<String,Typed<?>> fix(String name, Typed<?> entity) @ L56
- 方法名:fix
- 源码定位:L56
- 返回类型:Pair<String,Typed<?>>
- 修饰符:protected abstract
参数:
- name: String
- entity: Typed<?>
说明:
TODO
代码
public abstract class EntityRenameFix extends DataFix {
protected final String name;
public EntityRenameFix(String name, Schema outputSchema, boolean changesType) {
super(outputSchema, changesType);
this.name = name;
}
@Override
public TypeRewriteRule makeRule() {
TaggedChoiceType<String> oldType = (TaggedChoiceType<String>)this.getInputSchema().findChoiceType(References.ENTITY);
TaggedChoiceType<String> newType = (TaggedChoiceType<String>)this.getOutputSchema().findChoiceType(References.ENTITY);
Function<String, Type<?>> patchedInputTypes = Util.memoize(name -> {
Type<?> type = oldType.types().get(name);
return ExtraDataFixUtils.patchSubType(type, oldType, newType);
});
return this.fixTypeEverywhere(
this.name,
oldType,
newType,
ops -> input -> {
String oldName = input.getFirst();
Type<?> oldEntityType = patchedInputTypes.apply(oldName);
Pair<String, Typed<?>> newEntity = this.fix(oldName, this.getEntity(input.getSecond(), ops, oldEntityType));
Type<?> expectedType = newType.types().get(newEntity.getFirst());
if (!expectedType.equals(newEntity.getSecond().getType(), true, true)) {
throw new IllegalStateException(
String.format(Locale.ROOT, "Dynamic type check failed: %s not equal to %s", expectedType, newEntity.getSecond().getType())
);
} else {
return Pair.of(newEntity.getFirst(), newEntity.getSecond().getValue());
}
}
);
}
private <A> Typed<A> getEntity(Object input, DynamicOps<?> ops, Type<A> oldEntityType) {
return new Typed<>(oldEntityType, ops, (A)input);
}
protected abstract Pair<String, Typed<?>> fix(final String name, final Typed<?> entity);
}