EntityRidingToPassengersFix.java

net.minecraft.util.datafix.fixes.EntityRidingToPassengersFix

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public EntityRidingToPassengersFix(Schema outputSchema, boolean changesType) @ L20

  • 构造器名:EntityRidingToPassengersFix
  • 源码定位:L20
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L24

  • 方法名:makeRule
  • 源码定位:L24
  • 返回类型:TypeRewriteRule
  • 修饰符:public

参数:

说明:

TODO

private <OldEntityTree,NewEntityTree,Entity> TypeRewriteRule cap(Schema inputSchema, Schema outputType, Type<OldEntityTree> oldEntityTreeType, Type<NewEntityTree> newEntityTreeType, Type<Entity> entityType) @ L34

  • 方法名:cap
  • 源码定位:L34
  • 返回类型:<OldEntityTree,NewEntityTree,Entity> TypeRewriteRule
  • 修饰符:private

参数:

  • inputSchema: Schema
  • outputType: Schema
  • oldEntityTreeType: Type
  • newEntityTreeType: Type
  • entityType: Type

说明:

TODO

代码

public class EntityRidingToPassengersFix extends DataFix {
    public EntityRidingToPassengersFix(Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType);
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        Schema inputSchema = this.getInputSchema();
        Schema outputSchema = this.getOutputSchema();
        Type<?> oldEntityTreeType = inputSchema.getTypeRaw(References.ENTITY_TREE);
        Type<?> newEntityTreeType = outputSchema.getTypeRaw(References.ENTITY_TREE);
        Type<?> entityType = inputSchema.getTypeRaw(References.ENTITY);
        return this.cap(inputSchema, outputSchema, oldEntityTreeType, newEntityTreeType, entityType);
    }
 
    private <OldEntityTree, NewEntityTree, Entity> TypeRewriteRule cap(
        Schema inputSchema, Schema outputType, Type<OldEntityTree> oldEntityTreeType, Type<NewEntityTree> newEntityTreeType, Type<Entity> entityType
    ) {
        Type<Pair<String, Pair<Either<OldEntityTree, Unit>, Entity>>> oldType = DSL.named(
            References.ENTITY_TREE.typeName(), DSL.and(DSL.optional(DSL.field("Riding", oldEntityTreeType)), entityType)
        );
        Type<Pair<String, Pair<Either<List<NewEntityTree>, Unit>, Entity>>> newType = DSL.named(
            References.ENTITY_TREE.typeName(), DSL.and(DSL.optional(DSL.field("Passengers", DSL.list(newEntityTreeType))), entityType)
        );
        Type<?> oldEntityType = inputSchema.getType(References.ENTITY_TREE);
        Type<?> newEntityType = outputType.getType(References.ENTITY_TREE);
        if (!Objects.equals(oldEntityType, oldType)) {
            throw new IllegalStateException("Old entity type is not what was expected.");
        } else if (!newEntityType.equals(newType, true, true)) {
            throw new IllegalStateException("New entity type is not what was expected.");
        } else {
            OpticFinder<Pair<String, Pair<Either<OldEntityTree, Unit>, Entity>>> entityTreeFinder = DSL.typeFinder(oldType);
            OpticFinder<Pair<String, Pair<Either<List<NewEntityTree>, Unit>, Entity>>> newEntityTreeValueFinder = DSL.typeFinder(newType);
            OpticFinder<NewEntityTree> newEntityTreeFinder = DSL.typeFinder(newEntityTreeType);
            Type<?> oldPlayerType = inputSchema.getType(References.PLAYER);
            Type<?> newPlayerType = outputType.getType(References.PLAYER);
            return TypeRewriteRule.seq(
                this.fixTypeEverywhere(
                    "EntityRidingToPassengerFix",
                    oldType,
                    newType,
                    ops -> input -> {
                        Optional<Pair<String, Pair<Either<List<NewEntityTree>, Unit>, Entity>>> passenger = Optional.empty();
                        Pair<String, Pair<Either<OldEntityTree, Unit>, Entity>> updating = input;
 
                        while (true) {
                            Either<List<NewEntityTree>, Unit> passengersValue = DataFixUtils.orElse(
                                passenger.map(
                                    p -> {
                                        Typed<NewEntityTree> newEntity = newEntityTreeType.pointTyped(ops)
                                            .orElseThrow(() -> new IllegalStateException("Could not create new entity tree"));
                                        NewEntityTree newEntityTree = newEntity.set(
                                                newEntityTreeValueFinder, (Pair<String, Pair<Either<List<NewEntityTree>, Unit>, Entity>>)p
                                            )
                                            .getOptional(newEntityTreeFinder)
                                            .orElseThrow(() -> new IllegalStateException("Should always have an entity tree here"));
                                        return Either.left(ImmutableList.of(newEntityTree));
                                    }
                                ),
                                Either.right(DSL.unit())
                            );
                            passenger = Optional.of(Pair.of(References.ENTITY_TREE.typeName(), Pair.of(passengersValue, updating.getSecond().getSecond())));
                            Optional<OldEntityTree> riding = updating.getSecond().getFirst().left();
                            if (riding.isEmpty()) {
                                return passenger.orElseThrow(() -> new IllegalStateException("Should always have an entity tree here"));
                            }
 
                            updating = new Typed<>(oldEntityTreeType, ops, riding.get())
                                .getOptional(entityTreeFinder)
                                .orElseThrow(() -> new IllegalStateException("Should always have an entity here"));
                        }
                    }
                ),
                this.writeAndRead("player RootVehicle injecter", oldPlayerType, newPlayerType)
            );
        }
    }
}

引用的其他类

  • Schema

    • 引用位置: 参数
  • Entity

    • 引用位置: 参数/返回值