EntityHorseSplitFix.java

net.minecraft.util.datafix.fixes.EntityHorseSplitFix

信息

  • 全限定名:net.minecraft.util.datafix.fixes.EntityHorseSplitFix
  • 类型:public class
  • 包:net.minecraft.util.datafix.fixes
  • 源码路径:src/main/java/net/minecraft/util/datafix/fixes/EntityHorseSplitFix.java
  • 起始行号:L12
  • 继承:EntityRenameFix
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

public EntityHorseSplitFix(Schema outputSchema, boolean changesType) @ L13

  • 构造器名:EntityHorseSplitFix
  • 源码定位:L13
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected Pair<String,Typed<?>> fix(String name, Typed<?> entity) @ L17

  • 方法名:fix
  • 源码定位:L17
  • 返回类型:Pair<String,Typed<?>>
  • 修饰符:protected

参数:

  • name: String
  • entity: Typed<?>

说明:

TODO

代码

public class EntityHorseSplitFix extends EntityRenameFix {
    public EntityHorseSplitFix(Schema outputSchema, boolean changesType) {
        super("EntityHorseSplitFix", outputSchema, changesType);
    }
 
    @Override
    protected Pair<String, Typed<?>> fix(String name, Typed<?> entity) {
        if (Objects.equals("EntityHorse", name)) {
            Dynamic<?> tag = entity.get(DSL.remainderFinder());
            int type = tag.get("Type").asInt(0);
 
            String newName = switch (type) {
                case 1 -> "Donkey";
                case 2 -> "Mule";
                case 3 -> "ZombieHorse";
                case 4 -> "SkeletonHorse";
                default -> "Horse";
            };
            Type<?> newType = this.getOutputSchema().findChoiceType(References.ENTITY).types().get(newName);
            return Pair.of(newName, Util.writeAndReadTypedOrThrow(entity, newType, dynamic -> dynamic.remove("Type")));
        } else {
            return Pair.of(name, entity);
        }
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.writeAndReadTypedOrThrow()
  • EntityRenameFix

    • 引用位置: 继承